Updating GUI text on display

Started by pixelincognito, Fri 12/05/2017 11:57:08

Previous topic - Next topic

pixelincognito

Hi

A little like the 'UpdateInventory(); is there a way to update GUI details within the 'function room_Load()'? I have a GUI with various fields that take their data from global variable strings and integers but it looks a little ugly when these fields appear at their GUI default values to what they should actually appear as. This would be really handy for me in a number of other ways too so I hope something out there exists...that or I'm going about displaying my GUis in the wrong way.

Any help would be greatly appreciated.
Cheers!

Cassiebsg

Is this GUIs data to be updated constantly? Then change the values in rep_exe. If it only changes when the player does something specific, then change the value when that something happens.

Sorry if it's a little vague, but your question seems also a little vague, because the content of a gui changes only when you tell it to change.
There are those who believe that life here began out there...

Slasher

#2
To have your labels update automatically as they happen add this to repeatedly_execute_always in the Global

Example (Amend to your labels and global variables):
Code: ags

function repeatedly_execute_always() {
  LCoordsX.Text=(String.Format("%d",player.x*11));
  LCoordsY.Text=(String.Format("%d",player.y *3));
  LRescued.Text=(String.Format("%d",Rescued));
  LWhere.Text=(String.Format("from %s",Splinter_Group));
  LTRes.Text=(String.Format("%d",TotalRescued));
}


When ever you change a variable so does their label change as well...


pixelincognito

Thanks for the help.

I just wanted to limit the amount of work I was pushing into the auto_exec, and was curious if there was something I was missing. That's fine.

Cheers.

Khris

Just reorganize your code:
Code: ags
void UpdateMainGUI() {
  lblRoomInfo.Text = String.Format("...", room_info);
  ...
}

// built-in function that is called by AGS if defined
void on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) UpdateMainGUI(); // called in every room, before fade-in
}

  // somewhere in repeatedly_execute(), which only starts after fade-in
  UpdateMainGUI();

SMF spam blocked by CleanTalk