9-Verb Text?

Started by Armageddon, Fri 01/04/2011 01:54:34

Previous topic - Next topic

Armageddon

Hello, I don't know if this should be here or in the tech forum but since I'm a noob I'll put it here. So I'm making my own 9-verb gui from scratch, I have it all working right now. But the only thing I am missing, and can't figure out is that text that's always aove the gui. You know when you like scroll over Use and it will print 'Use' and then if you click to use something it would say 'Use Vending Machine' or 'Use Flashlight with Vending Machine' how would I go about doing this? I have looked through the code for the 9-verb module but it's just so bloated, all I really want it to do is have the verb come first then display the object that you want to use, display it's description that was set in the tools.

Sorry my writing might be a little incoherent.

Khris

How best to do this depends on how you implemented the 9 verbs.
You are either using a variable to store the currently selected verb or additional mouse modes, I presume.

In both cases, the action line is a label on a GUI and its text is updated inside repeatedly_execute.
Basically, the mouse.Mode / verb variable is translated into an action string, then GetLocationName() is inserted.

Example:
Code: ags
  if (action_verb == eActionPush) action_text = "Push";
  ...
  if (player.ActiveInventory != null) action_text = String.Format("Use %s with", player.ActiveInventory.Name);

  String location = Game.GetLocationName(mouse.x, mouse.y);
  if (!String.IsNullOrEmpty(location)) action_text = String.Format("%s %s", action_text, location);

  lblAction.Text = action_text;

Armageddon

Ok, so, like I said I am a total noob to all this, where exactly do I put that? And I'm not actually doing 9-verbs I'm just using 3 'Use' 'Talk' and 'Look'. If you could just explain this better that would be great. if not I'll try and figure it out on my own I guess. :-X

Khris

The code I posted goes inside the repeatedly_execute function in Global.asc.

You can't use it as-is, like I said it depends on your current setup. I assume you have the three action buttons on a GUI, what do they do i.e. what's in their OnClick functions?

Sephiroth

#4
Hello,

Here is a very basic example of custom interface:

-Create a Global Int called "CurrentVerb" from the right panel, default value "0".
-Add this code to the GlobalScript, the line: function on_mouse_click should already be here.
Code: ags


function on_mouse_click(MouseButton button) 
{
  // called when a mouse button is clicked. button is either LEFT or RIGHT

  Hotspot *h1;
  if (button == eMouseLeft)
  {

    if(GetLocationType(mouse.x, mouse.y) == eLocationHotspot)
    {
      h1 = Hotspot.GetAtScreenXY(mouse.x, mouse.y);
      if(CurrentVerb == 0)  //Use
      { 
        player.Walk(mouse.x, mouse.y, eBlock, eWalkableAreas); 
        player.Say(h1.Name);
        //other actions...
      }
      else if(CurrentVerb == 1)  //Talk
      { 
        player.Walk(mouse.x, mouse.y, eBlock, eWalkableAreas); 
        //Dialog
        //other actions...
      }
      else if(CurrentVerb == 2)  //Look
      { 
        player.Say(h1.Name);
        //other actions...
      }
    }

  }
  else if(button == eMouseRight)
  {

    if(CurrentVerb < 2)
     CurrentVerb++;
    else
     CurrentVerb = 0;

    if(CurrentVerb == 0) //use
    {
      //change cursor graphic to verb 0
     //play a sound
    }
    else if(CurrentVerb == 1) //talk
    {
      //change cursor graphic to verb 1
     //play a sound
    }
    else if(CurrentVerb == 2) //look
    {
      //change cursor graphic to verb 2
     //play a sound
    }
    
  }

}


This is just the concept, left click uses the currently selected verb on target hotspot, right click switches to next verb. This could be a good start.

Armageddon

Quote from: Khris on Fri 01/04/2011 05:56:13
The code I posted goes inside the repeatedly_execute function in Global.asc.

You can't use it as-is, like I said it depends on your current setup. I assume you have the three action buttons on a GUI, what do they do i.e. what's in their OnClick functions?
I have my button to do OnClick change to cursor. So, what I really want is, OnCursor.<GuiLabelName>.SetText "<verb name here>" I know it doesn't work like that but that's how I'd kinda see it working in my head, thanks for all your help, both of you. I still don't understand what the "CurrentVerb" means. ???

Sephiroth

#6
CurrentVerb represents the verb you are using at the moment, and will change whenever you change cursor.
You want to set the Label Text to the currently used verb? This should do :

Code: ags

if(CurrentVerb == 1)
 LabelName.Text = "Verb1";


Or replace lblAction.Text by your label name in Khris' example.
Is there something not clear about the code?

Armageddon

The CurrentVerb == 1 is 1 the number of the cursor? :=

Sephiroth

Quote
The CurrentVerb == 1 is 1 the number of the cursor?

The code means : If the selected verb is verb No 1 then change the label text to "verb1".

Khris

#9
Sorry if I'm sounding harsh here, but Sephiroth, your code seems to be aimed at creating the interface, not an action line, while Armageddon said he had a working interface already. Plus its incomplete (only Hotspots), and why would the player .Say the hotspot.Name, and only after a click? Clearly exactly NOT what Armageddon asked for.

Now, my code was not complete either but I think I finally have enough info to fill in the missing pieces:

Code: ags
function repeatedly_execute() {

  String action_text = "";
  if (mouse.Mode == eModeLook) action_text = "Look at";
  if (mouse.Mode == eModeUse) action_text = "Use";
  if (mouse.Mode == eModeTalkto) action_text = "Talk to";
  if (mouse.Mode == eModeUseinv) action_text = String.Format("Use %s with", player.ActiveInventory.Name);

  String location = Game.GetLocationName(mouse.x, mouse.y);
  if (!String.IsNullOrEmpty(location)) action_text = String.Format("%s %s", action_text, location);

  lblAction.Text = action_text;    // CHANGE lblAction TO THE NAME OF YOUR LABEL

  // REST OF REPEATEDLY EXECUTE CODE
}


Armageddon, in the future please don't confuse people with talking about a 9-verb GUI when you have three and put enough info in your very first post or at least provide it as soon as it is asked for.
I don't get why people don't post their friggin code when they want it to be expanded by others.

Edit: corrected code

Sephiroth

#10
Yeah sorry if that was useless but I may have misunderstood, read too fast ;)

Quote
So I'm making my own 9-verb gui from scratch
...
if you click to use something it would say 'Use Vending Machine' or 'Use Flashlight with Vending Machine'

I just wanted to show the events layout as an example, the rest of the code is random of course. Again if you're using basic cursors and actions then there's no such thing as "from scratch"  :P

Quote
I don't get why people don't post their friggin code when they want it to be expanded by others.
+1 !

Armageddon

#11
Well the thing is, I don't actually have any code otehr than the custom made save and load GUIs I made and the settings GUI, I remade all the GUIs to look very SCUMM-ish buttons and my few rooms and objects. Khris I think this code will work, I'll try it out in a moment, thank you both again for all the help, the hard part for me about making an ags game is the UI, once that is done I think making all the art will be easy enough for me. ;D

EDIT: I have one more small question, I don't think it needs its own thread, but how do you make it so that make it so that you can walk with all the cursors? Like in Sam and Max Hit the Road. Since I do not have a walk verb.

Khris

All you do is change the way a click is handled.

In on_mouse_click, a left click leads to ProcessClick() being called:

Code: ags
  else if (button == eMouseLeft) {
    ProcessClick(mouse.x, mouse.y, mouse.Mode);
  }


As you know, interacting with a blank part of the background doesn't do anything, so in that case, call Walk:

Code: ags
  else if (button == eMouseLeft) {
    int lt = GetLocationType(mouse.x, mouse.y);
    if (lt == eLocationNothing) ProcessClick(mouse.x, mouse.y, eModeWalkto);
    else ProcessClick(mouse.x, mouse.y, mouse.Mode);
  }

Armageddon

#13
It's giving me this parse error at 'else' thing, and when I move it around some it works, but it doesn't walk in-game. I'm not really understanding this, this is for the mouse click walk thing, I have yet to try the text thing. :'(

EDIT: Ok tried the verb changing thing and am getting this when I compile.


Khris

In line 64, try
Code: ags
  String action_text = "";

Armageddon

Ok I did that, it kinda works, but I want it to display the cursor name, right now it only shows something if I do use <inventory item> with. And if I change cursors while that's up it just keeps the same text, talk and use don't display any text.. :-\

Khris

Yeah, well, that's what happens if we don't know what you're doing on your end.
Look at lines 65-67: those put the verb in the line depending on the current cursor mode. If you aren't using the default ones, you'll obviously have to change the conditions to match yours.

Armageddon

Ok I think I may have explained that wrong. It all works fine when I start the game, it switches when I'm on a different cursor mode and stuff. BUT when I use an inventory item, the text is never cleared.

Code: ags
function repeatedly_execute() {
  
  // put anything you want to happen every game cycle, even when
  // the game is paused, here
  
  if (IsGamePaused() == 1) return;

  // put anything you want to happen every game cycle, but not
  // when the game is paused, here
  String action_text = "";
  if (mouse.Mode == eModeLookat) action_text = "Look";
  if (mouse.Mode == eModeInteract) action_text = "Use";
  if (mouse.Mode == eModeTalkto) action_text = "Talk";
  if (player.ActiveInventory != null) action_text = String.Format("Use %s with", player.ActiveInventory.Name);

  String location = Game.GetLocationName(mouse.x, mouse.y);
  if (!String.IsNullOrEmpty(location)) 
    action_text = String.Format("%s %s", action_text, location);

  Text_Label.Text = action_text;    // CHANGE lblAction TO THE NAME OF YOUR LABEL

  // REST OF REPEATEDLY EXECUTE CODE
}


I'm sorry. :(

Khris

Ok, sorry, I completely misunderstood that.
I think I know what's wrong, in line 68, try
Code: ags
  if (mouse.Mode == eModeUseinv) ...

Armageddon

YAY! It works almost perfectly, just one last thing, when I scroll over the inventory items the text updates before I click, but when I scroll over the verbs the text only updates if I click. Also, I may be able to figure this one out on my own. But I'm having the verbs display as 'Talk' 'Use' 'Look' when I scroll over or select a hotspot/inventory item I'd like talk and look to change to 'Talk to %s' and 'Look at %s'. Any ideas. ???

SMF spam blocked by CleanTalk