Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: pixelincognito on Fri 12/05/2017 11:57:08

Title: Updating GUI text on display
Post by: pixelincognito on Fri 12/05/2017 11:57:08
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!
Title: Re: Updating GUI text on display
Post by: Cassiebsg on Fri 12/05/2017 13:26:59
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.
Title: Re: Updating GUI text on display
Post by: Slasher on Fri 12/05/2017 14:34:29
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) Select

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...

Title: Re: Updating GUI text on display
Post by: pixelincognito on Fri 12/05/2017 14:44:58
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.
Title: Re: Updating GUI text on display
Post by: Khris on Fri 12/05/2017 16:17:54
Just reorganize your code:
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();