小编use*_*993的帖子

如何结束Lua中的循环协程?

我目前正在使用Roblox(使用Lua)进行游戏.它基本上由几个小游戏组成.在每轮开始时,游戏中的所有玩家都被放入桌子并被传送到一个区域.这是协程开始发挥作用的地方.随着回合的进行,我想要一个协程开始.协程每一秒检查玩家的健康状况是否低于零,并将其从currentPlayer表中移除(如果是).

对不起,如果我没有正确描述问题,但协程将不会产生.我之前没有使用过协同程序,所以我可能试图以错误的方式使用它.我知道你们大多数人都不熟悉Roblox,但是Lua的语法是一样的.

有人可以给我一个例子,说明如何结束循环协程吗?

currentPlayers = {}
roundTime = 60

local lookForWinners = coroutine.create(function()
  while coroutine.running do
    wait(1)
    for i, v in pairs(currentPlayers) do
      if v.Character.Humanoid.Health <= 0 then
        table.remove(currentPlayers, v)
      end
    end
  end
end)


while wait() do
  repeat display("Two or more players need to be in the game.", 1) until #_G.plrs > 1 --Ignore, just checks if two+ players are in game.
  display("Picking a map...", 3) pickMap()
  teleport(0, 500, 0)
  coroutine.resume(lookForWinners)
  wait(roundTime)
  print("Round over")
  coroutine.yield(lookForWinners)
end
Run Code Online (Sandbox Code Playgroud)

lua roblox

5
推荐指数
1
解决办法
3539
查看次数

How to get this simple assembly to run?

这是我第一次尝试用汇编编程。我使用的是 64 位 Mac 操作系统。我也在使用 NASM。我已经做了很多寻找解决方案的工作,但我找不到任何适合我的机器的东西。

谁能帮我解决这个问题?这是代码和错误,谢谢!

你好.asm

    global start

    section .text
start:
    mov rax, 1
    mov rdi, 1
    mov rsi, message
    mov rdx, 13
    syscall
    mov eax, 60
    xor rdi, rdi
    syscall
message:
    db "Hello, World", 10  
Run Code Online (Sandbox Code Playgroud)

我尝试执行:

nasm -f macho64 hello.asm -o hello.o
ld -arch i386 -o hello hello.o
./hello
Run Code Online (Sandbox Code Playgroud)

错误

ld: warning: -macosx_version_min not specified, assuming 10.10
ld: warning: ignoring file hello.o, file was built for unsupported file format ( 0xCF 0xFA 0xED 0xFE 0x07 0x00 0x00 …
Run Code Online (Sandbox Code Playgroud)

macos assembly linker x86-64 nasm

5
推荐指数
1
解决办法
1654
查看次数

如何解决我在尝试将C++与Assembly链接时遇到的链接器错误?

我正在尝试链接C++文件和程序集文件.Assembly文件定义了一个名为的C++函数add.我正在使用64位Mac OS.我尝试编译程序时收到以下错误:

Undefined symbols for architecture x86_64:
  "_add", referenced from:
      _main in main-d71cab.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main.o] Error 1
Run Code Online (Sandbox Code Playgroud)

Makefile文件

hello: main.o hello.o
  g++ main.o hello.o -o hello

hello.o: hello.asm
  nasm -f macho64 hello.asm -o hello.o

main.o: main.cpp
  g++ main.cpp -o main.o   
Run Code Online (Sandbox Code Playgroud)

hello.asm

global add

segment .text
add:
  mov           rax, rdi
  add           rax, rsi
  ret
Run Code Online (Sandbox Code Playgroud)

main.cpp中

#include <iostream> …
Run Code Online (Sandbox Code Playgroud)

macos 64-bit assembly linker g++

4
推荐指数
1
解决办法
751
查看次数

Lua随机数?

如何生成每次运行脚本时都不同的随机整数?我目前正在做一个“不可能的测验”,它使用随机数从表格中选择一个问题。每次我运行脚本时,问题的顺序都是相同的。我还使用 table.remove() 在提出问题后从表中删除问题。然而,一旦被删除,它就会继续问同样的问题,因为它没有选择一个新的随机数(我正在使用 math.random(1, #Questions) 从“问题”表中选择一个随机问题.)

    local lives = 3

Questions = {
    {"What is the magic word?", "lotion"},
    {"Does anyone love you?", "no"},
    {"How many fingers do you have?", "10"},
    {"What is 1 + 1?", "window"}
}

function lookForAnswer(ans)
    table.remove(Questions[number])
    local input = io.read() tostring(input)
    if input:lower() == ans then
        return true
    end
    lives = lives - 1
    if lives <= 0 then
        exit()
    end
    return false
end

for i = 1, #Questions do
    number = math.random(1, #Questions)
    local …
Run Code Online (Sandbox Code Playgroud)

random lua

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

assembly ×2

linker ×2

lua ×2

macos ×2

64-bit ×1

g++ ×1

nasm ×1

random ×1

roblox ×1

x86-64 ×1