Page 1 of 1

Changing texts from the Global Code

PostPosted: Tue Feb 07, 2012 11:50 pm
by mcavalcanti
Hi! I'm trying to change texts from inside the Global Code, but nothing is happening.
I put it in the Global Code:

Code: Select all
char stagename[] = "Stage 1 - Bay Area";
sprintf(stage.text, "%s", stagename);

But when I go to game mode, text object is empty.

Re: Changing texts from the Global Code

PostPosted: Wed Feb 08, 2012 12:13 am
by skydereign
Code in global space doesn't execute itself. It is only meant for declarative type code. So, you can put that sprintf into a function, and call the function in an event, otherwise your code will never execute.
Code: Select all
char stagename[] = "Stage 1- Bay Area";

void
display_stage_level ()
{
    sprintf(stage.text, "%s", stagename);
}

That way you can call the function elsewhere.
button -> Mouse Button Down Left -> Script Editor
Code: Select all
display_stage_level();


Do watch out though, you should try to avoid using actor.variable in global code. Generally speaking it won't work, unless the event that is calling the function has the actor's name explicitly in it. In this case I bypassed that problem by inserting stage into the function's name, that way by definition it will be in the event.