Changing texts from the Global Code

Non-platform specific questions.

Changing texts from the Global Code

Postby mcavalcanti » Tue Feb 07, 2012 11:50 pm

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.
Mario Cavalcanti
----------------------------
Code is poetry.
User avatar
mcavalcanti
 
Posts: 54
Joined: Fri Jul 22, 2011 1:09 am
Location: Rio de Janeiro, Brazil
Score: 1 Give a positive score

Re: Changing texts from the Global Code

Postby skydereign » Wed Feb 08, 2012 12:13 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest