showing variable value in message/GUI label

Started by Dan2552, Thu 11/12/2003 23:06:58

Previous topic - Next topic

Dan2552

how can i show a variable value in a GUI label?

RickJ

#1
Use the SetLabelTest(...) function.  See online help for more details.  

-----Edited to say Text, not Test
Use the SetLabelText(...) function.  See online help for more details.  

Reno Caspain

The normal C style works too. So in a message you can use it like this:

display("The variable is %d",variablename);

Where %d indicates where the variable listed later is displayed.

Dan2552

Quote from: RickJ on Fri 12/12/2003 04:48:26
Use the SetLabelTest(...) function.  See online help for more details.  
I havnt a clue what You're talking about? and this is online help...



Quote from: Reno Caspain on Fri 12/12/2003 07:57:56
The normal C style works too. So in a message you can use it like this:

display("The variable is %d",variablename);

Where %d indicates where the variable listed later is displayed.

I tried this:

if (button == 4)
Display ("You have %d Kashes.",Kashes);

but it says: "Error: undefined symbol 'Kashes'
when it is defiently a variable. How does it work???

SSH

Quote from: Dan2552 on Fri 12/12/2003 17:24:17
Quote from: RickJ on Fri 12/12/2003 04:48:26
Use the SetLabelTest(...) function.  See online help for more details.  
I havnt a clue what You're talking about? and this is online help...

Typo from Rick there:

SetLabelText (int gui, int object, string newtext)

Changes the text displayed in the specified label to NEWTEXT

Example:

string buffer;
GetLocationName(mouse.x,mouse.y,buffer);
SetLabelText(2,3,buffer);

will display on text box 3 of GUI 2 the name of the location the cursor is over.
Quote
Quote from: Reno Caspain on Fri 12/12/2003 07:57:56
The normal C style works too. So in a message you can use it like this:

display("The variable is %d",variablename);

Where %d indicates where the variable listed later is displayed.

I tried this:

if (button == 4)
Display ("You have %d Kashes.",Kashes);

but it says: "Error: undefined symbol 'Kashes'
when it is defiently a variable. How does it work???

Where have you declared it as a variable? It should be at the top of your global script. (and you may want to add it to the header too, see the manual)
12

evilspacefart

Quoteif (button == 4)
Display ("You have %d Kashes.",Kashes);

but it says: "Error: undefined symbol 'Kashes'
when it is defiently a variable. How does it work???

is the variable defined on that same script?

ie: int Kashes;

if not you may have to import it:

import int Kashes;

but before that it has to be exportable which you can set up in the global script:

int Kashes;
export int Kashes;

I don't know if this may be the issue..

Dan2552

in game it now says blah blah blah 0 kashes, now how do i change the variable? ive confused myself......

Scorpiorus

Kashes = 1;

will set that variable a new value (1 in that case)

~Cheers

Dan2552

Quote from: Scorpiorus on Sat 13/12/2003 22:18:44
Kashes = 1;

will set that variable a new value (1 in that case)

~Cheers

can you make it ADD intead of change the whole variable?

Scorpiorus


Dan2552


Dan2552

#11
it still says 0 when i put:
Display ("You have %d Kashes.",Kashes);

when i have clearly changed the variable:
Kashes = Kashes + 2;

What have I done wrong now!?

edit--
sorry about the double post, axident

Scorpiorus

#12
be sure you display variable after you changed it's value:

Kashes = Kashes + 1;
Display ("You have %d Kashes.", Kashes);

EDIT: also if you declared a variable within function's body it's value get reset each time function is called:

function some_function() {
int Kashes; //resets each time function is called
}

If you want a static variable place it outside of  function's body:

//room or main global script

int Kashes; //static

function some_function() {

}

~Cheers

Dan2552

i have:

// main global script file
int Kashes;
int pot;

 // script for hotspot1: Interact hotspot
if (pot == 0) {
DisplayMessage (6) ;
Kashes = Kashes + 2;
pot = 1;
}

// script for inventory5: Look at inventory item
Display ("You have %d Kashes.",Kashes);


Scorpiorus

Ah, I see - you probably declared two other variables int Kashes and int pot within the room script, right? But they are different (although their names are identical) to those in the main global script, therefore when you click on a hotspot AGS changes local room variables, not global ones. But you display a value of global variables (that is in the main script).

Instead you need to export variables to the room:

//main global script

int Kashes;
int pot;

// script for inventory5: Look at inventory item
Display ("You have %d Kashes.", Kashes);

//at the end of the global script
export Kashes;
export pot;

//room script

import int Kashes;
import int pot;


// script for hotspot1: Interact hotspot
if (pot == 0) {
DisplayMessage (6) ;
Kashes = Kashes + 2;
pot = 1;
}

Dan2552

#15
the pot one works perfectly. i will try your theory


edit-----
WOOO! THANKS!

Im guessing i have to import in every room that the variable changes?

Scorpiorus

#16
You need to import only if you want a variable to be read/written from both global and room scripts. So, in the example above you could declare a pot variable in the room only leaving Kashes still be exported:

//global script

int Kashes; //only Kashes here (as we want to display it from the global script's inventory item function)

// script for inventory5: Look at inventory item
Display ("You have %d Kashes.", Kashes);

//at the end of the global script
export Kashes; // Kashes only

room script

import int Kashes; //importing Kashes from the global script
int pot; // declaring pot just here for that room only


// script for hotspot1: Interact hotspot
if (pot == 0) {
DisplayMessage (6) ;
Kashes = Kashes + 2;
pot = 1;
}

QuoteIm guessing i have to import in every room that the variable changes?
If you want to include a global variable into every new room you create just put it in the script header which is added ontop of each script (both main global and local room):

//script header

import int Kashes; // now Kashes is imported into every  new room we create.

ps You still need to export it though.

~Cheers

SMF spam blocked by CleanTalk