Dynamic Code in Studio
Posted 02 May 2012 - 03:22 AM
For me, in other languages, I would use an array of function pointers and store in the map file the function index and the value of its arguments in an array. Then every command would just be an array reference and passing the array of parameters. But I don't think GM allows for function pointers. Does it? I suppose I could do an array of objects with a User defined event in each that is called every time to perform the event's action. However, I would think that is overkill especially if you want to have hundreds of event functions. I don't know GM well enough to know if that would be a load on the engine.
So my final thought is to use a switch style statement to find the appropriate event function. This seems to be a bit clunky and lead to a lot of unnecessary comparisons. So back to my question: How do you plan to deal with dynamic scripting in your game using Studio?
Posted 02 May 2012 - 07:02 AM
// Equivalent g = gauss(0,1.66667); g = script_execute(gauss,0,1.66667);
You still can't construct code a run-time, but script_execute() can solve most of these sorts of challenges.
If any of my posts contain broken images or links, I can probably supply them for you. PM with a link to the post.
Posted 02 May 2012 - 11:44 AM
I think that would go a long way to allow script calls to be data driven which is what is needed for external level editors. GM's room editor is good for basic stuff but production slows when you are trying to do something that is specific to your game. An external editor can help cut down on the workload by doing some of the heavy lifting for you. But there needs to be a way to make GM's function calls, data driven for that to work nicely.
EDIT: I did some playing around and you can assign a script to a variable and then execute the variable using the script_execute() statement. For instance:
global.testfunctionid = testscript script_execute(global.testfunctionid)
where testscript is a script with a single call to room_goto_next() acted as a wrapper for that function. Therefore I may be able to do my first idea and assign each script to an index of an array and use the index as the script identifier in the map file.
Thanks for your help.
Edited by redspark, 02 May 2012 - 05:16 PM.