Post subject: Specific question regarding a work-around for execute_string
Posted: Mon Mar 30, 2015 3:09 pm
Lucario and/or Braixen = best avatar
I posted this in the GMC, but I figured chances of finding a solution would come quicker if I shared this here as well. I've been looking around the internet for an answer, and while I've found some answers that have been useful, I have yet to find an answer to a specific question regarding a work around for execute_string in GMStudio, and I'm honestly stumped as to how I can find a work around.
I know you can use data structures to change variables, but what if you want a specific object or objects to perform a specific set of actions? For example, in a previous project I worked on, I had cutscene objects make characters or other objects perform specific actions, like make them move around or create an instance at a certain position and make the created object set a variable in itself, like a flag to stay with the player, to true, using the cutscene object's creation code.
Here's the above example explained with a little more detail:
In SMBOdyssey Ch.2, and in the cutscene object's creation code, I told it to call a script that went to execute_string and created a speech bubble at Mario's position, but Mario was walking and the speech bubbles are stationary by default, so I told it to set it's flag to stick with a specific cutscene character to true, and set a variable in the speech bubble that told it to stick to Mario's instance ID's position. The code was a little messy (particularly as I hadn't learned of some better methods of doing things), but it looked like this:
^^ This one comes from a separate cutscene. Toad had fallen down and is dizzy, so I told the cutscene object to create little stars around his head.
Code:
cs_code("with (151619) instance_destroy(); with (151387) fall_fast = true;")
^^ This code comes from the same cutscene. An invisible platform (which kept Mario from falling as soon as the cutscene started) is destroyed and Mario begins falling, but with a flag set to true so that his max vspeed is capped at a higher value than his default falling speed
shard[1] = instance_create(x+4,y+26,obj_shard); with shard[1] motion_set(75,3); shard[2] = instance_create(x+4,y+26,obj_shard); with shard[2] motion_set(40,3);
shard[3] = instance_create(x-4,y+26,obj_shard); with shard[3] motion_set(105,3); shard[3] = instance_create(x-4,y+26,obj_shard); with shard[3] motion_set(140,3); }")
^^Same cutscene. When Mario lands on the ground, since he was falling faster, I added eye candy to exaggerate the force of his landing. He generates both smoke and ground particles, which kick up into the air upon him landing.
The code above added the string of code from cs_code to a list that the cutscene controller object went down to see what actions it should perform next. The string "Code" in the first line would be used by the cutscene controller in a switch statement to see what type of action it was performing. In the cutscene controller object, in the switch statement I mentioned above was this:
Code:
case "Code": execute_string(ds_list_find_value(list,0)); ds_list_delete(list,0); break;
the string of code from the cutscene object's creation code in cs_code is executed here and is then removed from the list to prevent the list from becoming too large and eventually crashing the game.
This was able to save me a lot of time, especially as I never was able to find a work-around, but now that I'm using GMStudio and this feature is absent, I need a work around for this. I've searched and searched but I just can't figure it out.
Any advice?
I posted this in the GMC, but I figured chances of finding a solution would come quicker if I shared this here as well. I've been looking around the internet for an answer, and while I've found some answers that have been useful, I have yet to find an answer to a specific question regarding a work around for execute_string in GMStudio, and I'm honestly stumped as to how I can find a work around.
I know you can use data structures to change variables, but what if you want a specific object or objects to perform a specific set of actions? For example, in a previous project I worked on, I had cutscene objects make characters or other objects perform specific actions, like make them move around or create an instance at a certain position and make the created object set a variable in itself, like a flag to stay with the player, to true, using the cutscene object's creation code.
Here's the above example explained with a little more detail:
In SMBOdyssey Ch.2, and in the cutscene object's creation code, I told it to call a script that went to execute_string and created a speech bubble at Mario's position, but Mario was walking and the speech bubbles are stationary by default, so I told it to set it's flag to stick with a specific cutscene character to true, and set a variable in the speech bubble that told it to stick to Mario's instance ID's position. The code was a little messy (particularly as I hadn't learned of some better methods of doing things), but it looked like this:
in obj_cutscene's creation code in the room:
[code]cs_code("speechbubble = instance_create(0,0,obj_speech_exclamation); speechbubble.stickwithplayer = true; speechbubble.character = (151449)")[/code]
Here's a few more examples of how I used it if anyone needs a bit of a better idea:
[spoiler][code]cs_code("spk = instance_create((151614).x+choose(-8,-6,-4,-2,0,2,4,6,8),(151614).y-choose(0,2,4,6),obj_smoke); spk.sprite_index = spr_firework_sparkle3")[/code]
^^ This one comes from a separate cutscene. Toad had fallen down and is dizzy, so I told the cutscene object to create little stars around his head.
[code]cs_code("with (151619) instance_destroy(); with (151387) fall_fast = true;")[/code]
^^ This code comes from the same cutscene. An invisible platform (which kept Mario from falling as soon as the cutscene started) is destroyed and Mario begins falling, but with a flag set to true so that his max vspeed is capped at a higher value than his default falling speed
[code]cs_code("with (151387)
{
smoke[0] = instance_create(x,y+26,obj_smoke);
smoke[0].hspeed = 0.5;
smoke[0].depth = depth-1;
smoke[1] = instance_create(x,y+26,obj_smoke);
smoke[1].hspeed = 1;
smoke[1].depth = depth-1;
smoke[2] = instance_create(x,y+26,obj_smoke);
smoke[2].hspeed = 1.5;
smoke[2].depth = depth-1;
smoke[3] = instance_create(x,y+26,obj_smoke);
smoke[3].hspeed = -0.5;
smoke[3].depth = depth-1;
smoke[4] = instance_create(x,y+26,obj_smoke);
smoke[4].hspeed = -1;
smoke[4].depth = depth-1;
smoke[5] = instance_create(x,y+26,obj_smoke);
smoke[5].hspeed = -1.5;
smoke[5].depth = depth-1;
shard[1] = instance_create(x+4,y+26,obj_shard);
with shard[1] motion_set(75,3);
shard[2] = instance_create(x+4,y+26,obj_shard);
with shard[2] motion_set(40,3);
shard[3] = instance_create(x-4,y+26,obj_shard);
with shard[3] motion_set(105,3);
shard[3] = instance_create(x-4,y+26,obj_shard);
with shard[3] motion_set(140,3);
}")[/code]
^^Same cutscene. When Mario lands on the ground, since he was falling faster, I added eye candy to exaggerate the force of his landing. He generates both smoke and ground particles, which kick up into the air upon him landing.[/spoiler]
cs_code:
[code]ds_list_add(list,"Code");
ds_list_add(list,argument0);[/code]
The code above added the string of code from cs_code to a list that the cutscene controller object went down to see what actions it should perform next. The string "Code" in the first line would be used by the cutscene controller in a switch statement to see what type of action it was performing. In the cutscene controller object, in the switch statement I mentioned above was this:
[code]case "Code":
execute_string(ds_list_find_value(list,0));
ds_list_delete(list,0);
break;[/code]
the string of code from the cutscene object's creation code in cs_code is executed here and is then removed from the list to prevent the list from becoming too large and eventually crashing the game.
This was able to save me a lot of time, especially as I never was able to find a work-around, but now that I'm using GMStudio and this feature is absent, I need a work around for this. I've searched and searched but I just can't figure it out.
Any advice?
Post subject: Re: Specific question regarding a work-around for execute_st
Posted: Sat Apr 04, 2015 11:43 am
C# Programmer
Could you do something with storing functions and parameters in a list or some collection and executing each one in order? You can even have a flag for each function determining whether the action has completed. I'll elaborate later with some examples.
Could you do something with storing functions and parameters in a list or some collection and executing each one in order? You can even have a flag for each function determining whether the action has completed. I'll elaborate later with some examples.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum