HELP ! show on label "walk to" when the walk to button it's clicked

Started by santitassara, Thu 25/06/2020 01:22:04

Previous topic - Next topic

santitassara

Hello!
well i want my label to show "walk to X direction" when the walk to button is clicked . i know it has to be somewhere in the forum but i just can't find it, i tried really hard to find it but nothing appears.
please help .
Thanks!  :smiley:

Slasher

You could have something like this in Global.asc

Normal Walk is not blocked..

Code: ags

function repeatedly_execute() 
{
 LWalk.Text=String.Format("Walk to %d, %d",player.x, player.y);
}


You could use mouse.x,mouse.y and that will change  x y to the position of the mouse..

Others may have better ways..


arj0n

Quote from: santitassara on Thu 25/06/2020 01:22:04
i want my label to show "walk to X direction" when the walk to button is clicked .

Slashers example shows the player coordinates constantly while walking, I think he misunderstood your question.
I think your looking for something like this:

in this example, the gui has a textlabel called L_WTD.

Now, in your Global script edit the existing eMouseLeft part of the function on_mouse_click(MouseButton button) function.
Make it like this:

Code: ags

function on_mouse_click(MouseButton button) {
  // called when a mouse button is clicked. button is either LEFT or RIGHT
  if (IsGamePaused()) 
  {
    // Game is paused, so do nothing (ie. don't allow mouse click)
  }
  else if (button == eMouseLeft) 
  {
    if (mouse.Mode==eModeWalkTo)
    {
      String wtt = String.Format ("walk to %d, %d direction", mouse.x, mouse.y);
      WTx = mouse.x;
      WTy = mouse.y;
      L_WTD.Text = wtt;
    }
  }
  ...
}


Optionally, to clear the label text once the player has reached the clicked coordinates, add this line in the rep. execute in your global script
Code: ags

function repeatedly_execute() {
  if ((player.x == WTx) && (player.y == WTy)) L_WTDo.Text = "";
  ...
}
:

Finally, on top of your global script add:
Code: ags

// main global script file
int WTx;
int WTy;



Crimson Wizard

I wonder if "X direction" mean coordinates, actual mathematical direction (vector), words like LEFT, RIGHT,etc or just hotspot name, like "Walk to Table"?

arj0n

Quote from: Crimson Wizard on Thu 25/06/2020 11:43:30
I wonder if "X direction" mean coordinates, actual mathematical direction (vector), words like LEFT, RIGHT,etc or just hotspot name, like "Walk to Table"?
mmhh... could be indeed. I assumed it was about coordinates. if it isn't about them, my example is also misunderstood  ;)

eri0o


santitassara

thank you all for answering.
when i said "walk to X" i meaned "walk to table" , "walk to livingroom" or "walk to park" like a hotspot or a region also an item .
my mistake not knowing it could be missunderstood .

still don't know how to do it , i'm new at this and it's a bit tricky to me. also i'm doing this on mac so everytime i have to try something it has to be on a virtual machine.
thanks .

Slasher

I  use a Label to capture cursor mode. I call it LMode.

You then need a Label with the text @OVERHOTSPOT@ to get description of hotspot or object.

Code: ags

function repeatedly_execute_always() {
if(mouse.Mode==1){
 LMode.Text=String.Format("Look at...");
} if(mouse.Mode==2){
 LMode.Text=String.Format("Interact with...");
}if(mouse.Mode==3){
 LMode.Text=String.Format("Talk to...");
} if(mouse.Mode==4){
 LMode.Text=String.Format("Use %s with...",player.ActiveInventory.Name);

}
}


Line the Labels up so you get like:

Walk to... Table     
Interact with... Swing

etc etc

Khris

Use slasher's code but insert the name of the active area, like this:

Code: ags
function repeatedly_execute() {
  String text = "Verb";
  switch (mouse.Mode) {
  case eModeWalkto:
    text = "Walk to"; break;
  case eModeInteract:
    text = "Interact with"; break;
  case eModeTalkto:
    text = "Talk to"; break;
  case eModeUseinv:
    text = String.Format("Use %s with", player.ActiveInventory.Name);
  }
  lblAction.Text = String.Format("%s %s", text, Game.GetLocationName(mouse.x, mouse.y));
}

SMF spam blocked by CleanTalk