GUI label error [SOLVED]

Started by Da_Elf, Sun 24/12/2006 14:34:32

Previous topic - Next topic

Da_Elf

whats wrong with this script.
Code: ags
lblStatus.Text = GetGlobalInt ("daytime"); 


in my glabal script ive already set the code "int daytime=1;" (without quotes)
but when i go to test the game i get the error.
--
Error (line 211); type mismatch; cannot convert 'const string to 'int'
--

Ali

#1
This should work:

Code: ags
lblStatus.Text = daytime;


A variable that you've defined yourself isn't a Global Int. Global Ints are identified by integer numbers rather than strings (which is what caused: cannot convert 'const string to 'int'). They're useful because you can alter them from within dialogue scripts.

Da_Elf

im using this in each rooms section "repeatedly execute" as a script. since the int was defined in the global script i get an error saying "undefined symbol 'daytime'"

when i move this code to the global script and place it right below where i state int daytime = 1 i get an error saying "parse error: unexpected 'lblStatus'"

Ali

#3
Try putting the line in repeatedly_execute in the global script.

If you do want to use this line in a room script rather than the global script, you need to export and import the variable:

At the end of the global script:
Code: ags
export daytime;


In the Global Header script:
Code: ags
import int daytime;


EDIT: SSH is absolutely right. You listen to him, now. I don't know how I didn't spot that.

SSH

The problem is, ints or global ints or whatever are of type "integer" and a label text is type String. So you need to do:

lblStatus.Text = String.Format("%d", daytime);

For easier globalints, try my DeNGVaT module.

And do you actuially have a GUI label called "lblStatus"? ANd does the previous line have a semicolon?
12

Da_Elf

#5
ok. i did the suggestion of exporting the int so that i can use it in a rooms repeatedly execute script and i think it has the exact same effect as using getglobalint ("daytime") since I'm now back to getting the error "type mismatch; cannot convert 'int' to 'string*' is it possible that i cant use int to define a label?

EDIT thanks SSH It worked perfectly. yup there is the label called lblStatus...i decided also to keep it in the global repeatedly_execute area

SMF spam blocked by CleanTalk