Refresh issue of Actor (script editor)

Non-platform specific questions.

Refresh issue of Actor (script editor)

Postby johngalt00 » Fri Jul 19, 2013 3:01 pm

Hi!


I have a problem with refresh of actors. I hope someone can help me.

I have a score actor. If I want to rise this score on special event I just call score.textNumber = newscore;

If I write this code at the scripteditor for a mouseButtonDown Event directly it works and the actor is updated on the screen.
But if I call there a function like writeScore(); and define this function at a global script area this not works.

Can some one explain me why this happens?

Thanks
johngalt00
 
Posts: 6
Joined: Mon Jun 17, 2013 11:20 am
Score: 0 Give a positive score

Re: Refresh issue of Actor (script editor)

Postby Lacotemale » Fri Jul 19, 2013 4:04 pm

Global script area is for functions. You must execute those functions somewhere else.

writeScore(); might want to be called in place where the player scores.

EDIT: If you post some code it might be easier to help you.
User avatar
Lacotemale
 
Posts: 285
Joined: Wed Dec 08, 2010 7:47 pm
Location: /home
Score: 7 Give a positive score

Re: Refresh issue of Actor (script editor)

Postby AliceXIII » Fri Jul 19, 2013 5:28 pm

The mouse down event is the "refresh" cause the event triggers an action in your case a script where you would call your global function if this is not your problem then it's with your writeScore() function.
"Taking a breath of fresh air."
User avatar
AliceXIII
 
Posts: 325
Joined: Fri Sep 17, 2010 2:36 am
Location: victoria, texas
Score: 37 Give a positive score

Re: Refresh issue of Actor (script editor)

Postby johngalt00 » Mon Jul 22, 2013 8:09 am

I try to explain better with a sample.

I have an actor with the name "button" and an actor "scores".
If I click on the actor button I want to add 1 to point to the score.
So what I do is to add an Action "Mouse Button Down" at the "button" Actor, create there Script Editor and write the code:

loadVars("global","scores");
points = points + 1;
score.textNumber = points;
saveVars("global","scores");

This works and I have a correct value at the vars and also a right value at the screen which show me the right value at the score.textNumber.

Now I have 4 buttons and want to have done the same. So I write a global function

void writeButton() {
loadVars("global","scores");
points = points + 1;
score.textNumber = points;
saveVars("global","scores");
}

And at each button I create the Event "Mouse Button Down" at at each I write at the Script Editor this call:

writeButton();

Now I have the right value at the variable but the value on the screen show me the old value and not the new one. And I not understand why?

thx
johngalt00
 
Posts: 6
Joined: Mon Jun 17, 2013 11:20 am
Score: 0 Give a positive score

Re: Refresh issue of Actor (script editor)

Postby skydereign » Mon Jul 22, 2013 8:19 am

johngalt00 wrote:Now I have the right value at the variable but the value on the screen show me the old value and not the new one. And I not understand why?

This is due to an odd problem in how gE handles actor variables. You can read about it in these posts.
http://game-editor.com/forum/viewtopic.php?f=1&t=12249#p86907
http://game-editor.com/forum/viewtopic.php?f=2&t=12196#p86444

The general thing is that you need to have some reference to the actor in the actual event code (otherwise it won't actually set the variable in global code). The workaround is to put a comment with the actor's name before the function call.
Code: Select all
// score
writeButton();
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Refresh issue of Actor (script editor)

Postby johngalt00 » Mon Jul 22, 2013 9:26 am

Ah. Great!
Thank you. Now it works! :)
johngalt00
 
Posts: 6
Joined: Mon Jun 17, 2013 11:20 am
Score: 0 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron