Jump to content




Help with chatbox command system


5 replies to this topic

#1 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 16 November 2017 - 04:25 PM

I was trying to one-up nago with a chatbox-based command interpreter that would have modular commands that could run asynchronously upon activation, so that followup input could be read. However, I cannot get that to work. Right now it just hangs until you reboot with CTRL+R. How do I do this?

Link to pastebin: https://pastebin.com/ECeJ3CpL

Let me explain its intended action.

Instances of commands being ran are stored in the userActions table. When any external command is ran (found in "/chatcommand/cmd/"), it will create a coroutine of a function of that command being ran with the first argument being the user who ran the command, and the rest being an arbitrary amount of extra arguments. When a command is done executing, it's supposed to be removed automatically from the userActions table. A person would chat a command, then it would look for all external commands and check too see if the user command matched. Failing that, it would check the internal ones instead.
Of course, none of that happens, because it hangs immediately. It doesn't return a "too long without yield" though.

If I get this to work, this could be my big chance to learn the ins and outs of coroutines, and I could make new, wonderful things!

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 16 November 2017 - 04:31 PM

You aren't passing any events, which your commands probably need. Also, this sounds like a great place to use my statemachine API.

#3 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 16 November 2017 - 05:10 PM

View PostKingofGamesYami, on 16 November 2017 - 04:31 PM, said:

You aren't passing any events, which your commands probably need. Also, this sounds like a great place to use my statemachine API.

That looks really useful, but the functions that run in the chatbox command interpreter are in a table that needs to be indexed with strings. Can functions asynchronously ran by statemachine be named, individually terminated, and stored in a table? The instructions on the forum post didn't seem to demonstrate that exactly.

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 16 November 2017 - 05:23 PM

Yes. The API is designed to give you as much control as possible, without having to deal with co-routines.
Something like this would work:
local tFuncs = {} --# put a bunch of functions here
local tFuncAsyncs = {}
for k, v in pairs( tFuncs ) do
  tFuncAsyncs[ k ] = statemachine.unblock( v )
end
statemachine.setLoop( function()
  for k, v in pairs( tFuncAsyncs ) do
    if v() then
      tFuncAsyncs[ k ] = nil
    end
  end
end )

Edit: I have a project demonstrated here which shows a bit more of what you can do. It's not 100% working and I may have slightly abandoned the project, but it's there.

Edited by KingofGamesYami, 16 November 2017 - 05:35 PM.


#5 LDDestroier

  • Members
  • 1,095 posts
  • LocationACDC Town

Posted 16 November 2017 - 06:55 PM

View PostKingofGamesYami, on 16 November 2017 - 05:23 PM, said:

-snip-

After a bit of modifying, I got it working. I think it will work for other people too, so I'll test further on a multiplayer server. Thanks for the help, your API really saved my ass.

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 16 November 2017 - 07:02 PM

Thanks :) I think this is the first time someone has actually used it (besides me), so I'm glad you found it useful.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users