making the gui

Started by randypana, Sat 06/07/2013 20:57:51

Previous topic - Next topic

randypana

hi i am making a gui and make a label, that I can do to change the word label such as: open door, and if I put something else: talking to elaine
I'm busy doing nothing ;)

monkey0506

Code: ags
// GlobalScript.asc

String GetCursorText(this Mouse*) // function to get the current cursor mode text
{
  if (this.Mode == eModeWalkto) return "Walk to"; // check cursor mode and return relevant text
  else if (this.Mode == eModeLookat) return "Look at";
  else if (this.Mode == eModeInteract) return "Use";
  else if (this.Mode == eModePickup) return "Pick up";
  else if (this.Mode == eModeTalkto) return "Talk to";
  else if (this.Mode == eModeUseinv)
  {
    // if mode is Useinv, make sure player has valid active inventory
    if ((player.ActiveInventory != null) && (!String.IsNullOrEmpty(player.ActiveInventory.Name)) return String.Format("Use %s on", player.ActiveInventory.Name);
    else return "Use";
  }
  else return null;
}

function repeatedly_execute()
{
  String loc = Game.GetLocationName(mouse.x, mouse.y); // location name
  String cur = mouse.GetCursorText(); // get cursor text (as defined above)
  if (cur == null) // cursor invalid, no text given
  {
    if (String.IsNullOrEmpty(loc)) lblLocation.Text = ""; // if location also is unnamed, blank out label text
  }
  else if (String.IsNullOrEmpty(loc)) lblLocation.Text = cur; // if cursor is valid but location unnamed, set label to cursor text
  else lblLocation.Text = String.Format("%s %s", cur, loc); // else both are valid, assign to label
}

randypana

#2
Quote from: monkey_05_06 on Sat 06/07/2013 21:24:06
Code: ags
// GlobalScript.asc

String GetCursorText(this Mouse*) // function to get the current cursor mode text
{
  if (this.Mode == eModeWalkto) return "Walk to"; // check cursor mode and return relevant text
  else if (this.Mode == eModeLookat) return "Look at";
  else if (this.Mode == eModeInteract) return "Use";
  else if (this.Mode == eModePickup) return "Pick up";
  else if (this.Mode == eModeTalkto) return "Talk to";
  else if (this.Mode == eModeUseinv)
  {
    // if mode is Useinv, make sure player has valid active inventory
    if ((player.ActiveInventory != null) && (!String.IsNullOrEmpty(player.ActiveInventory.Name)) return String.Format("Use %s on", player.ActiveInventory.Name);
    else return "Use";
  }
  else return null;
}

function repeatedly_execute()
{
  String loc = Game.GetLocationName(mouse.x, mouse.y); // location name
  String cur = mouse.GetCursorText(); // get cursor text (as defined above)
  if (cur == null) // cursor invalid, no text given
  {
    if (String.IsNullOrEmpty(loc)) lblLocation.Text = ""; // if location also is unnamed, blank out label text
  }
  else if (String.IsNullOrEmpty(loc)) lblLocation.Text = cur; // if cursor is valid but location unnamed, set label to cursor text
  else lblLocation.Text = String.Format("%s %s", cur, loc); // else both are valid, assign to label
}

thanks hope this is I need is, greetings ;-D
I'm busy doing nothing ;)

Jaffles

Thinking about putting something like this in a game I'm working on. Does this work on hotspots as well as objects/characters?
   

Kitai


monkey0506

Granted, it's a bit passive-aggressive on my part, posting the code without a single word. But this is one of the most commonly asked beginner questions. For more robust solutions you may want to take a look at the Description module, because that offers variant solutions as to how and where the text is displayed. The code snippet I provided should be enough to get you the basic idea, and it serves as a relatively simple introduction to the development process in AGS (because scripting is required). I even provided comments to help walk you through it. :P

SMF spam blocked by CleanTalk