Page 1 of 1

Getglobal and setglobal

PostPosted: Mon May 12, 2008 3:30 am
by catacomber
Can you use getglobal()

--item in parenthesis would be name of global --

and setglobal() in GE to query the status of a global variable?

Re: Getglobal and setglobal

PostPosted: Mon May 12, 2008 12:38 pm
by makslane
Just set the value by using the = operator:

Code: Select all
yourvariable = newvalue;

Re: Getglobal and setglobal

PostPosted: Mon May 12, 2008 2:20 pm
by catacomber
Thank you, Makslane. Unless you or someone else tells me otherwise, I'll assume it's the same for

getstate()

and

setstate()

state=1;


?

Or it doesn't work in the same way in GE?
Global variables are enough for me--can do a lot with them but am interested to know about states as well.
Thanks for your help.

: )

Re: Getglobal and setglobal

PostPosted: Mon May 12, 2008 3:33 pm
by makslane
You don't need create a function to change a variable value.

Re: Getglobal and setglobal

PostPosted: Mon May 12, 2008 8:48 pm
by catacomber
Thank you! One more question and I will leave people in peace for awhile. : )

To display a message in the world, do you have to use a text actor or is there a function that will display a text, f.e.
dislplay a string constant, like Hello World.

printf?

That's my question------how many ways are there

to say

"Hello World" in G.E. ? :D Only one? Using a text actor and colliding or something?

Am making a small 2d rpg game--I've looked at the "rpg style talk" demo but am hoping for a simpler way to "talk".

Re: Getglobal and setglobal

PostPosted: Tue May 13, 2008 12:11 am
by makslane
You need to use a text actor, and put some code like:

Code: Select all
strcpy(text, "Hello World");

Re: Getglobal and setglobal

PostPosted: Tue May 13, 2008 3:29 am
by catacomber
Thanks, Makslane. :D

Re: Getglobal and setglobal

PostPosted: Thu May 15, 2008 2:02 am
by catacomber
I'm so excited! Figured out how to make strcopy work!!!!

I made a text actor that said "Silence". The color of Silence is a bright orange so you can really see it.

Then on Collision of my player actor with a pillar, changed "Silence" to say "You need to touch a different pillar"!

Collision Player with Pillar
Script Editor

strcpy(Txt.text,"You need to touch a different pillar");

Txt is the name of the text actor that said "Silence" before.

Well, it's very exciting to me. : ) Now to figure out other things to do with it.

I needed something like this to do a pillar puzzle. : ) ) Of course you don't need text to do a pillar puzzle but it is sometimes nice.

Re: Getglobal and setglobal

PostPosted: Fri May 16, 2008 3:41 am
by catacomber
I'm further excited---found out that sprintf works the same way as strcpy---just substitute sprintf for strcpy with similar setup as above--on collision with object using same code except substitute sprintf for strcpy----magically my new text appears instead of the old:

sprintf(Txt.text,"You need to touch a different pillar");

So---is there any different use for sprintf as opposed to what strcpy does? Or is the result the same? Is using one more efficient than using the other?

Re: Getglobal and setglobal

PostPosted: Fri May 16, 2008 12:06 pm
by Fuzzy
sprintf is more versatile.

Re: Getglobal and setglobal

PostPosted: Fri May 16, 2008 12:11 pm
by makslane
sprintf is a C function for make formatted strings.

Read more here:
http://www.elook.org/programming/c/sprintf.html
http://www.elook.org/programming/c/printf.html

Re: Getglobal and setglobal

PostPosted: Fri May 16, 2008 2:50 pm
by catacomber
Thanks, Fuzzy, thanks, Makslane - those were very helpful. Using that code I made my archer collide with a tombstone to test it out--code on collision with tombstone:

char a[20] = "Player";
int age = 21;
sprintf(Display.text,"Hello %s, you are %d years old\n", a, age);

Before the archer collided, my text actor said: "Display".

After Archer collided with the tombstone, my text actor (which was Display before) said: Hello, Player you are 21 years old, as in pic.

Thanks also to Pyrometal for helping me understand this clearly. :D

Now to think of ways to manipulate this. :D You all and GE and this forum are great!