Order of Code Execution

Learn how to make certain types of games and use gameEditor.

Order of Code Execution

Postby DrakeStoel » Sun May 15, 2016 8:25 am

This is an incredibly noobey question, I'm sure, but how do you choose what order your code executes in? For example, I have this piece of code that activates on collision on the bottom side of a filled region actor:

Code: Select all
EventDisable("Event Actor", EVENTALL);
yvelocity = 0;
ChangeAnimation("Event Actor", "1", FORWARD);
ChangeZDepth("player_collide", 0.000000);
MoveTo("Event Actor", 0.000000, 20.000000, 1.000000, "player", "");


But when I run it, my actor just continues going up, I'm assuming because the EventDisable line prevents the rest of it occurring, but I need to turn off all the events otherwise you can fidget around, but it is ment to simulate going down stairs while facing upwards, pretty much like entering a cave in the original Zelda for NES.

Any tips for making this work, or is it possible to set the order of execution? Thanks for your help in advance!
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score

Re: Order of Code Execution

Postby skydereign » Sun May 15, 2016 9:35 pm

You can't change the order of code execution for editor functions (though you don't need to in this case). The EventDisable won't stop the rest of the code from running. In your example the event actor should be changing their animation to 1. One question that might help, is your event actor the player? The MoveTo is moving the event actor down 20 pixels of the player actor, which leads me to believe the event actor is different from the player actor. And if that is the case you might be wanting to either disable the events of a different actor, or set the yvelocity of another actor to 0. From your bit of code there seem to be four different actors (Event Actor, player_collide, player, and Collide Actor), is that actually true?
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Order of Code Execution

Postby DrakeStoel » Sun May 15, 2016 10:12 pm

Oh I see! I've figured it out. I thought that it should work as well without an order of execution, but I found the problem.

So, I only have three actors involved, "player," "player_collide," and the collision actor, "Event Actor" was simply "player," which was also the problem. "player_collide" is the parent of my player for activation of other events and what not, but doesn't actually have any events itself (except to set it to a draw only state) which also happened to be the problem. I was trying to move the player, when I should have been moving "player_collide."

Here's the updated code (just in case anyone else can learn from my mistake):

Code: Select all
EventDisable("Event Actor", EVENTALL);
yvelocity = 0;
ChangeAnimation("Event Actor", "1", FORWARD);
ChangeZDepth("player_collide", 0.000000);
MoveTo("player_collide", 0.000000, 20.000000, 0.7500000, "player_collide", "");


Thanks so much skydereign for helping realize what was going wrong!
DrakeStoel
 
Posts: 43
Joined: Wed Oct 03, 2012 8:53 am
Score: 2 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest