D
Danei
Guest
So, I have a turn-based RPG in development where you have an overworld map and local encounters which you will be able to exit in a variety of ways, and I use essentially the following code, in a script that is called from a player object not referenced in the code.
Anyway, as I was coding this I realized, "wait, this probably won't work because I'm declaring the local variables dirStr and exitType in my player object, but trying to access them in my cursor object", but I tried it on a whim and to my surprise it works just fine. So my question is why does it work? Not that I'm complaining. But I would have expected the local variables not to be available to the object that is calling them. I could have sworn I ran into that exact issue a lot when I was first learning with 1.4. Does the fact that all of this is occurring within one script have anything to do with it? I'm using the current version of GMS2.
Just curious. Thanks!
Code:
//scr_tryToLeave(direction);
var dir = argument0;
var dirStr = "test";
if (dir == 360) dirStr = "East.";
if (dir == 270) dirStr = "South.";
if (dir == 180) dirStr = "West.";
if (dir == 90) dirStr = "North.";
// Determine whether we're fleeing or traveling normally (not yet implemented)
[INDENT]var exitType = "Flee";[/INDENT]
with (obj_encounter){ //exit encounter and move back to world map
instance_destroy();
}
with (obj_cursor){
actionString = exitType+dirStr; //set exit message
scr_pushMessage(actionString); //display exit message
}
Just curious. Thanks!