Page 1 of 1

Refresh issue of Actor (script editor)

PostPosted: Fri Jul 19, 2013 3:01 pm
by johngalt00
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

Re: Refresh issue of Actor (script editor)

PostPosted: Fri Jul 19, 2013 4:04 pm
by Lacotemale
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.

Re: Refresh issue of Actor (script editor)

PostPosted: Fri Jul 19, 2013 5:28 pm
by AliceXIII
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.

Re: Refresh issue of Actor (script editor)

PostPosted: Mon Jul 22, 2013 8:09 am
by johngalt00
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

Re: Refresh issue of Actor (script editor)

PostPosted: Mon Jul 22, 2013 8:19 am
by skydereign
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();

Re: Refresh issue of Actor (script editor)

PostPosted: Mon Jul 22, 2013 9:26 am
by johngalt00
Ah. Great!
Thank you. Now it works! :)