Assign string variable to GUI label <SOLVED>

Started by MusicallyInspired, Sat 21/06/2008 04:13:56

Previous topic - Next topic

MusicallyInspired

I have a GUI on the bottom of the screen where there are 2 labels. One shows the hotspot that the cursor is floating over and the other I want to show a short room description of the room the player is currently in. I tried doing this by having a global string variable named RoomDescription which isn't initialized. Upon loading each room it sets RoomDescription to its own description and in the global RepeatedlyExecute function it assigns the GUI label the string inside RoomDescription. I've tried doing this by just trying to straight assign a string to it, by having a local variable in each room with the description and assigning it to the global RoomDescription but that doesn't work either. I've also tried String.Format when assigning the room's description variable to the global RoomDescription and last but not least I've tried the Copy() function. Nothing works so far. Any help would be nice.
Buy Mage's Initiation OST (Bandcamp)
Buy Mage's Initiation (Steam, GOG, Humble)

Mazoliin

#1
Let's see if I have understood this right. Then this might be some help for you.

Code: ags

//Top of global script
String RoomDescription;
export RoomDescription;

//In the script header
import String RoomDescription;

//in repeatedly execute
lblLABEL.Text = "%s", RoomDescription;

//An then you just need to change the string every time you want a new description.

MusicallyInspired

Ah thank you. I forgot to do the export/import thing. I thought that wasn't necessary if you put it in just the global header scriot,
Buy Mage's Initiation OST (Bandcamp)
Buy Mage's Initiation (Steam, GOG, Humble)

Khris

Don't declare variables in the header because you'll get independent vars for each room then.
I'd do:
Code: ags
// global script

String room_desc[50];

function SetUpRoomDescriptions() {
  room_desc[1] = "Blah...";
  room_desc[2] = "Blah...";
  ...
}

function game_start() {
  ...
  SetUpRoomDescriptions();
}

function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    label.Text = room_desc[data];
  }
  ...
}

Pumaman

It's worth noting that AGS 3.0.2 is now out, which includes a Global Variable Editor and means in future you should no longer have to do all the farting around with import/export.

SMF spam blocked by CleanTalk