Text actor not updated by change to text in global script

Non-platform specific questions.

Text actor not updated by change to text in global script

Postby Cleve Blakemore » Wed May 21, 2008 1:09 pm

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.
Cross Platform executable generation in a 4GL C-Scripted Compiler? I've got your Game Maker hanging right here.
Cleve Blakemore
 
Posts: 26
Joined: Wed Feb 16, 2005 2:42 am
Score: 1 Give a positive score

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

Postby pyrometal » Wed May 21, 2008 1:51 pm

I had to do the same thing as you did before, its rather annoying.... I wonder, why doesn't it work? Does anyone know?
SPRITE WARRIOR:
Free, open-source & crossplatform pixel art editor (currently under construction).
User avatar
pyrometal
 
Posts: 706
Joined: Wed Nov 28, 2007 4:07 am
Location: Kingston, ON, Canada
Score: 86 Give a positive score

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

Postby makslane » Wed May 21, 2008 3:22 pm

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
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

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

Postby Cleve Blakemore » Wed May 21, 2008 10:54 pm

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.
Cross Platform executable generation in a 4GL C-Scripted Compiler? I've got your Game Maker hanging right here.
Cleve Blakemore
 
Posts: 26
Joined: Wed Feb 16, 2005 2:42 am
Score: 1 Give a positive score

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

Postby makslane » Thu May 22, 2008 12:11 am

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);
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

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

Postby Cleve Blakemore » Thu May 22, 2008 7:53 am

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.
Cross Platform executable generation in a 4GL C-Scripted Compiler? I've got your Game Maker hanging right here.
Cleve Blakemore
 
Posts: 26
Joined: Wed Feb 16, 2005 2:42 am
Score: 1 Give a positive score

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

Postby makslane » Thu May 22, 2008 11:40 am

Is just a workaround is not a perfect solution, sorry.
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

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

Postby Cleve Blakemore » Sun May 25, 2008 6:33 am

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.
Cross Platform executable generation in a 4GL C-Scripted Compiler? I've got your Game Maker hanging right here.
Cleve Blakemore
 
Posts: 26
Joined: Wed Feb 16, 2005 2:42 am
Score: 1 Give a positive score

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

Postby makslane » Sun May 25, 2008 4:02 pm

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.
Game Editor is an open source game creator software that's wants to pay it's developers to keep evolving.
If you like Game Editor, make a review!
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron