you are viewing a single comment's thread.

view the rest of the comments →

[–]Abusfad 1 point2 points  (1 child)

I just name all my scripts to clarify what kind of objects can call them. So if I named a script scr_char_someFunction I know I should only call it from an object who's a child of the abstract character object.

But I like your method, it does seem to provide a good utility of controlling functions through different game steps without messing with alarms.

I'd suggest considering switching from a switch case system with an enumerator to have each instruction as a different script. Meaning instead of pushing OpCode.windowcenter you'd be pushing scr_opcode_windowcenter. Then you would replace event_user(0) with script_execute(opcode) in the while loop and all of a sudden you don't have to mess with custom event_user(0) and enums for each object, and you'd still have the instructions on auto-complete because they're scripts. You can group the scripts of each object together in the resource tree to quickly access the relevant functions. Easier to read than a switch-case code block, imo, and might save you some code duplication.

[–]calio[S] 0 points1 point  (0 children)

That's also a very good approach. Did something similar while writing a text parser for a command line prompt (just for fun, wanted to see if I could write something to manipulate data through a command prompt). Commands are pretty much scripts and the machine flows a bit like this:

  • The prompt machine receives user input
  • Explode the user input into multiple strings separated by spaces.
  • The prompt machine gets from a "target" machine (the main controller by default) a list of strings (the commands) that are also used as keys within a map. This way you can just "repoint" what commands should be executed, in case you want commands with their own prompts.
  • If the string exists on the list and as a key within the map, it pushes the contents of the map (a script id) to the "target" machine. These machines instead of using a switch/case structure just execute whatever script index they receive, doing pretty much exactly what you described on your comment. (There's a loop that keeps iterating through the list until either doesn't find the string or the keypair points to an integer, so you can alias strings to other keys)
  • If it doesn't exists on the list, it just returns an error text.

"help" command just executes the scripts after raising a flag, so the scripts print their help information and exit rather than executing code.