Page 1 of 1

Global function problem

PostPosted: Sun Aug 19, 2012 7:00 pm
by Superbeni
I made a global function to load text from an array, and put in into the game, but i doesnt work as intended.

Function:
Code: Select all
void PM_Level_Reload()
{
strcpy(PM_Level1_Text.text, Level_Text[3]);
strcpy(PM_Level2_Text.text, Level_Text[2]);
strcpy(PM_Level3_Text.text, Level_Text[1]);
strcpy(PM_Level4_Text.text, Level_Text[0]);
}


I execute the function in another actor with
Code: Select all
PM_Level_Reload();


But when I start the game, and the funtion is executed, the text of PM_Level1_Text has changed, but to the value of null.

Does someone know, what i am doing wrong, or should i upload the whole game?

Re: Global function problem

PostPosted: Mon Aug 20, 2012 7:21 am
by skydereign
I've answered this question quite a few times recently. I should really make a wiki page on it. Anyway, long story short, it is a bug in gE. You can read more about it here.
http://game-editor.com/forum/viewtopic.php?f=1&t=12249#p86907
http://game-editor.com/forum/viewtopic.php?f=2&t=12196#p86444

Re: Global function problem

PostPosted: Mon Aug 20, 2012 7:40 am
by Superbeni
As I have multiple actors in that function, I cannot put all the names of them as a comment above the function, or can i?
I already tried putting one actor´s name above it, but, as i thought, it only worked for this actor, and every line overwrote the line before, so I cant use the function 4 times, too. (once for every actor)

I guess the easiest way would be to find another way to do whatever i want?

Re: Global function problem

PostPosted: Mon Aug 20, 2012 7:47 am
by skydereign
To work around the bug with the comment, you'd have to put each actor's name in the script (usually by comment). Other options include not using actor variables like that in global code or using the getclone fix mentioned in the second link.

Re: Global function problem

PostPosted: Mon Aug 20, 2012 10:39 am
by Superbeni
I finnaly got it, still quite surprised that it´s so easy:
Code: Select all
//PM_Level1_Text
//PM_Level2_Text
//PM_Level3_Text
//PM_Level4_Text
PM_Level_Reload();


Thanks a lot for your help!