Displaying variables on a GUI (SOLVED)

Started by Snake, Sat 02/12/2006 23:59:15

Previous topic - Next topic

Snake

Alright, I'm sorry about this, but I'm having a rediculously retard moment here.
In a previous game I was making (which is gone now since my other computer shit it's load) I was able to display lives. Did it all myself - which was a while ago for scripting. I'm doing something short right now that requires me to display LIVES. I can't be arsed to remember how the fuck I did it.
Something about string format and this crazy thing: %d...

Some one please help me quick and release me from this spell of stupidness... I've been reading the manual for the past half hour and I can't seem to understand a goddamned thing for the life of me. When I did it for the other game I was using an older version of AGS (before scripting changed... so maybe that's why I'm stooped.


Thanks in advance,


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Ubel

int Lives;

lblLives.Text = String.Format("Lives: %d", Lives);

Here of course lblLives is the text label where you want the lives to be displayed.

'Lives' is the variable where the amount of lives is stored.

It's of course a good idea to put this line of code in repeatedly_execute.

Snake

Size of identifier does not match prototype
Now what in God's creation does that mean?

I've got int Lives=6; in the start of the global script... and I've got lblLives.Text = String.Format("Lives: %d", Lives);.
Lives is the name of the label.


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Khris

Not sure if this is what causes the error, but lbl isn't like the g with GUIs or c with characters.
If the label is named Lives, use Lives.Text.

Snake

I kinda remember that, yeah.

I just tried it but it gives me the same error...


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Kweepa

You can't have a variable called Lives AND a label also called Lives.
Just call your variable numberOfLives instead and you should be good to go.

Code: ags

int numberOfLives = 6;
...
Lives.Text = String.Format("Lives: %d", numberOfLives);
Still waiting for Purity of the Surf II

Snake

Thanks, guys. I didn't realize that you couldn't have those two the same name... should've... but no suprise I didn't ;)


--Snake
Grim: "You're making me want to quit smoking... stop it!;)"
miguel: "I second Grim, stop this nonsense! I love my cigarettes!"

Ashen

Changing capitalisation would've helped, too (Lives vs. lives vs. LIVES).

Quote
lblLives.Text = String.Format("Lives: %d", Lives);

Personally, I name my GUI Controls like that anyway - so the label would actually be called lblLives and the above line would've worked.

For future reference, you might save time if you mention what you've tried and what is/isn't happening (as well as any error messages you've got) in your first post. And please, use descriptive thread titles. Seriously, you've been here longer than me, I should need to tell you this stuff  ;)
I know what you're thinking ... Don't think that.

SMF spam blocked by CleanTalk