• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code replacement of execute_string?

R

Re_hei

Guest
There was a 'execute_string' function before game maker: studio. (~8.1)
I need its function, but in game maker: studio and studio 2, there is no 'execute_string'.

Is there any replacement of this function?

Like this;
scr_text = "global.hp -= 1";

When 'execute_string' exists, 'execute_string(scr_text)' is same as writing 'global.hp -= 1'.

I need this function because of executing commands in my text engine.
It works like

message[0] = "/f[spr_smile]I like /c[c_white]pancakes/c[c_black]/n because of/s[bgm_shiny]/v[global.hp +=1] its sweety/i[obj_npc1] taste!/x[scr_flash]"

/f[spr_smile] will change the sprite as 'spr_smile',
/c[c_white] will change the color of text as white,
/s[bgm_shiny] will play the music 'bgm_shiny',
/v[global.hp += 1] will execute the code 'global.hp +=1'
/i[obj_npc1] will create the instance of 'obj_npc1',
/x[scr_flash] will execute the script 'scr_flash' and so on...
 

Mike

nobody important
GMC Elder
You don't need execute_string(), you can parse the string and look up variables using variable_instance_get() and then fill in the values. You just need something that parses strings and accepts commands via them.
 
S

Storyteller

Guest
an 'eval()' function like execute_string() would be nice, especially for creating genetic code. You can abstract it, but actually being able to build code out of ode can lead to pretty cool AI. Will execute_string() or an eval() function ever be replaced?
 

gnysek

Member
an 'eval()' function like execute_string() would be nice, especially for creating genetic code. You can abstract it, but actually being able to build code out of ode can lead to pretty cool AI. Will execute_string() or an eval() function ever be replaced?
languages which can be compiled into native code (not a virtual machines) doesn't support things like this (is there eval in C++?). You need to write your own parser - it is doable in about 1-2 hours in GMS, if you own last GMS Humble Bundle there is game called Solstice there and have parser to dialog events - very helpful example to how write own.

eval() is really unsafe and can be very dangerous in wrong hands.
 
S

Storyteller

Guest
Nope. Not currently in our list. Sorry.
cool, just wondering. most genetic algorithms can be written without it.

self modifying code however is much, much more difficult to do without the ability to create functions out of thin air. While a parser can be used to determine what to do that already is built in, you have to account for each code 'element' before hand.

That said, not implementing runtime self generating code is probably the safe route ;)
 
R

Re_hei

Guest
You don't need execute_string(), you can parse the string and look up variables using variable_instance_get() and then fill in the values. You just need something that parses strings and accepts commands via them.
Wow, thank you :)
 
Top