2
\$\begingroup\$

Last I checked, the game I'm modding was compiled* using Game Maker 8.0

So for a little set up, here is my situation. There's a game out there which has a box in which you can enter a string and it executes it. I decided to try and mod the game through use of this cheat box along with some other objects which execute strings and whatnot.

In general, this is all essentially powered by the built-in function 'execute_string'. My main problem is that as far as I know one cannot pass arguments to these executed strings, which is essential to anything complicated** I might wish to do.

I know there is a similar function called execute_script which allows for argument parameters to be passed into the code being executed. However, adding scripts as rescources is one of the many things that get "flushed" out of memory when saving/loading using the default save system. I am definitely not interested in reloading code from files on the fly and I don't want to make my own save system (which would still require code to be loaded from files) as I would prefer to basically have to use a save file and a few 3D model/image files to send the mod to anyone else who might be interested in it. I could also send the raw source, but regardless I don't want a lot of unstable resource manipulation.

So basically, is there a way for me to pass arguments into the code being executed with "execute_string" without having to implement my own function stack memory space and do the pushing and popping of arguments manually?


*The game was made many years ago in game maker 6.0. I believe it was recompiled for efficiency purposes.

**For instance, a very common technique to make some more complicated enemies or buildings is to make your own dynamic memory allocator using an array as a virtual memory space and use the interfaces of raw memory allocation to build lists and trees or whatever else you need. That is definitely something which requires a lot of different function calls.

\$\endgroup\$
  • 1
    \$\begingroup\$ It seems you need a text parser or something. Like, splitting a script into several functions, and executing every single one of them via execute_string(). At least, that's what I understand from your question. \$\endgroup\$ – liggiorgio Jun 3 '17 at 20:28
  • \$\begingroup\$ @liggiorgio absolutely not. What does a text parser have to do with asking how to pass arguments to code evaluated with execute_string()? \$\endgroup\$ – The Great Duck Jun 3 '17 at 21:27
  • \$\begingroup\$ @liggiorgio execute_string can already execute several lines of code. The issue is how to pass parameters to these strings and get them back. I don't see how a parser would help with that. Are you saying I need to write my own interpreter for the language from scratch? That sounds... a bit wasteful. \$\endgroup\$ – The Great Duck Jun 3 '17 at 22:03
  • 1
    \$\begingroup\$ Only Game Maker Studio 2 has all those features you want. Not even GMS 1 had. You don't have much choice if not do everything on your own, like liggiorgio said. \$\endgroup\$ – DH. Jun 3 '17 at 22:31
  • \$\begingroup\$ @DH. Did you even read my question? I'm not using Game Maker Studio and execute string already exists. Why would I need to write execute string from scratch? \$\endgroup\$ – The Great Duck Jun 3 '17 at 22:37
1
\$\begingroup\$

Here is a different answer, which might be more inclined towards what you wanted.

Read. The. Documentation.

From The GM 8.0 Docs/Game Maker Language/Changing Rescources/Scripts

execute_string(str,arg0,arg1,...) Execute the piece of code in the string str with the indicated arguments.

I'm just going to point out the need to whenever one does programming and wants to do something that might just be an unknown feature... to read the documentation. That's what it is for.

\$\endgroup\$
  • \$\begingroup\$ while true, the wording of this answer comes over to me as pretty rude, which is unnecesary. \$\endgroup\$ – Brian H. Feb 7 '18 at 12:41
  • \$\begingroup\$ @BrianH. surely you can see who asked the question, though? Note, it is a dig. \$\endgroup\$ – The Great Duck Feb 9 '18 at 5:47
0
\$\begingroup\$

Here is a potential solution:

Before any functions you wish to call:

FUNCTION_STACK[RECURSION_LEVEL+1,0] = arg_0;
FUNCTION_STACK[RECURSION_LEVEL+1,1] = arg_1;
....
FUNCTION_STACK[RECURSION_LEVEL+1,n] = arg_n;

At the beginning of any "functions" you wish to call, do the following:

RECURSION_LEVEL += 1;
//arguments found in "FUNCTION_STACK[RECURSION_LEVEL,__]"

When the function ends do the following:

RETURN_VALUES[RECURSION_LEVEL-1] = return value;

This is a pretty weird solution, but it should emulate the idea of calling user-defined functions.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.