Page 1 of 1

Text actor not updated by change to text in global script

PostPosted: Wed May 21, 2008 1:09 pm
by Cleve Blakemore
I have a bit of code I was trying to change one Text label with a sprintf command in a global subroutine, but strangely enough the value never showed up. I tried setting the Visibility to trigger a redraw but it didn't work correctly until I put the global value into the text variable in the DrawActor event for that Text actor. Nothing else seemed to work.

Re: Text actor not updated by change to text in global script

PostPosted: Wed May 21, 2008 1:51 pm
by pyrometal
I had to do the same thing as you did before, its rather annoying.... I wonder, why doesn't it work? Does anyone know?

Re: Text actor not updated by change to text in global script

PostPosted: Wed May 21, 2008 3:22 pm
by makslane
To change a value of a builtin variable (x, y, xscreen, text...) from a global code, you need to refer the actor thats will be changed in the caller actor.
For example, if your code changes the text of the actor label, put in the sctipt thats call the global code:

Code: Select all
//label

Re: Text actor not updated by change to text in global script

PostPosted: Wed May 21, 2008 10:54 pm
by Cleve Blakemore
I don't understand what you said in the post above.

I have a text actor. It's named "hours_remaining" and it has no clones.

In a global function, I call "sprintf(hours_remaining.text,"%i",intvalue);" and it never shows up in the actor.

So to work around this problem, I gave "hours_remaining" a DrawActor event and in the script editor I put a piece of code that says "sprintf(text,"%i",globalintvalue);" that seems to work fine. I try to avoid using DrawActor whenever possible but this seems to be the only way to reflect changes made in global variables and values in a text actor.

This is not that terrible a glitch but it is undocumented behaviour and so like many others I have to figure out how to work around it while creating a game.

Strangely enough, if in another actor's event code you change the text value of another actor, it always shows up. Even if it is scripted code as opposed to a behaviour created through the editor. It's only in snippets of global "C" code it does not appear to trigger a redraw to reflect the change. I can understand this, maybe it is tied to the nature of the way the event system works.

Re: Text actor not updated by change to text in global script

PostPosted: Thu May 22, 2008 12:11 am
by makslane
Look the docs:
http://game-editor.com/docs/scripting.htm

The only way to change a internal, or built in, actor variable in a global code is putting some reference, even a comment, in the caller script.

So, if youur global function is something like:

Code: Select all
void changeHours(int intvalue)
{
    sprintf(hours_remaining.text,"%i",intvalue);
}


When you call the changeHours function you must refer the hours_remaining actor to changes take effect:

Code: Select all
//hours_remaining
changeHours(2);

Re: Text actor not updated by change to text in global script

PostPosted: Thu May 22, 2008 7:53 am
by Cleve Blakemore
makslane wrote:Look the docs:
http://game-editor.com/docs/scripting.htm

The only way to change a internal, or built in, actor variable in a global code is putting some reference, even a comment, in the caller script.

Code: Select all
//hours_remaining
changeHours(2);


I thought that was a misprint in the documentation. I thought comments never affect the compiler. So referencing a control at the beginning of a comment is taken into account by the compiler and that affects the actor?

I think I understand but it seems strange. Would it be possible to have something more explicit in the code other than a comment, say:

Code: Select all
#SCOPE hours_remaining
changeHours(2);


... that would not use a comment? What about comments that have actor names embedded in them accidentally, say ...

Code: Select all
// this function is called by the hours_remaining label
changeHours(2);


... and how do you reference each clone in a group with similar syntax if you are iterating through a set of clones and setting some property in each, like in a for-next loop in a piece of global code? You could not add comments for each and every clone ...

Code: Select all
// hours_remaining.0
// hours_remaining.1
// hours_remaining.2
// hours_remaining.3
// hours_remaining.4
for(i = 0;i < numberOfActors;i++)
{
 DoSomething(ActorName(i));
} ... etc.


I always thought that was a misprint in the documentation because I thought all compilers ignore comments unless they have special syntax.

Re: Text actor not updated by change to text in global script

PostPosted: Thu May 22, 2008 11:40 am
by makslane
Is just a workaround is not a perfect solution, sorry.

Re: Text actor not updated by change to text in global script

PostPosted: Sun May 25, 2008 6:33 am
by Cleve Blakemore
So, I understand there may be problems with altering physical variables in global code and triggering an update.

Can you solve this by intercepting writes in the scripted code to actor variables and deliberately calling a routine to reflect these changes, no matter where it occurs from?

What about calling an actual function from global code, like VisibilityState? Doesn't this change the actor no matter what because it is a function write, not merely a write to an actor variable? I think I have experienced problems with these functions in global code.

Re: Text actor not updated by change to text in global script

PostPosted: Sun May 25, 2008 4:02 pm
by makslane
Can you solve this by intercepting writes in the scripted code to actor variables and deliberately calling a routine to reflect these changes, no matter where it occurs from?


This is the right solution.

What about calling an actual function from global code, like VisibilityState?


Calling actions in the global code must works.