Global function problem

Game Editor comments and discussion.

Global function problem

Postby Superbeni » Sun Aug 19, 2012 7:00 pm

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?
User avatar
Superbeni
 
Posts: 130
Joined: Sun Aug 02, 2009 1:23 pm
Location: Vienna, Austria
Score: 31 Give a positive score

Re: Global function problem

Postby skydereign » Mon Aug 20, 2012 7:21 am

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

Re: Global function problem

Postby Superbeni » Mon Aug 20, 2012 7:40 am

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?
User avatar
Superbeni
 
Posts: 130
Joined: Sun Aug 02, 2009 1:23 pm
Location: Vienna, Austria
Score: 31 Give a positive score

Re: Global function problem

Postby skydereign » Mon Aug 20, 2012 7:47 am

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

Re: Global function problem

Postby Superbeni » Mon Aug 20, 2012 10:39 am

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!
User avatar
Superbeni
 
Posts: 130
Joined: Sun Aug 02, 2009 1:23 pm
Location: Vienna, Austria
Score: 31 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest