Add a custom 4 verbs GUI to BASS template

Started by PaulineV, Tue 21/05/2019 21:13:29

Previous topic - Next topic

PaulineV

Hi !
I was wondering if there is any simple way (existing module or simple code) to add a 4-verbs-like system into a BASS template.
What I would like is to create a GUI with 4 icons/GuiButton (for 4 actions) : done
I would like that GUI to open when player clicks on an object and, according to the GUIbutton selected, run a specific action.

The 4 Verbs template was not the best option because I want this to happen only in specific conditions.

Thank you very much in advance !

Cassiebsg

#1
That sounds like you want to make a VerbCoin system.

Edit:
Also, you better off to throw the 2 click template out the window, instead of trying to modify it, cause a lot is hard coded to react to 2 buttons.
There a few templates on the forum, search for monkey's Verbcoin.

I have a game using a verbcoin, but I ended up coding my own as non of the available ones did what I wanted. I used monkey's code as a basis and to learn how it worked, and the edited it to serve my needs-
There are those who believe that life here began out there...

VampireWombat

I've done this before, actually. The problem is that the method I used meant having to click on the object to make the GUI appear, click on the action, and then click on the action again.
The GUI was positioned based on where the mouse was when clicked and used a String variable.

I'm sure there's a cleaner way to do it. But if you still want to do it built on the BASS system, I can provide some sample code.

morganw

There is a replacement for the current VerbCoin template that sounds a little like what you are asking for. I don't think many people have tried it, but you can download it from here if you want to give it a try. Maybe it will just be useful as an example of a context-sensitive GUI that pops-up, but the inventory system is pretty much the BASS one and I tried to keep it as simple as I could.

There also some basic instructions for it in the new manual:
https://adventuregamestudio.github.io/ags-manual/TemplateVerbcoin.html

Disclaimer: both of these items are effectively pre-release

PaulineV

Quote from: VampireWombat on Wed 22/05/2019 00:14:26
I've done this before, actually. The problem is that the method I used meant having to click on the object to make the GUI appear, click on the action, and then click on the action again.
The GUI was positioned based on where the mouse was when clicked and used a String variable.

I'm sure there's a cleaner way to do it. But if you still want to do it built on the BASS system, I can provide some sample code.

That's pretty much what I want to do, except for the "and then click on the action again"  :-D.
I managed to make a GUI appear exactly where the mouse is click but now I am stuck for what to do next.

Quote from: morganw on Wed 22/05/2019 00:29:32
There is a replacement for the current VerbCoin template that sounds a little like what you are asking for. I don't think many people have tried it, but you can download it from here if you want to give it a try. Maybe it will just be useful as an example of a context-sensitive GUI that pops-up, but the inventory system is pretty much the BASS one and I tried to keep it as simple as I could.

There also some basic instructions for it in the new manual:
https://adventuregamestudio.github.io/ags-manual/TemplateVerbcoin.html

Disclaimer: both of these items are effectively pre-release

Thanks morganw, il will look at it. The reason I thought templates were not the good solution is that they have a different system for inventory and I don't want to change the one I already have.

VampireWombat

Quote from: PaulineV on Wed 22/05/2019 08:34:34
That's pretty much what I want to do, except for the "and then click on the action again"  :-D.
I managed to make a GUI appear exactly where the mouse is click but now I am stuck for what to do next.
Oops. I meant click on the object again. And actually, that part can be bypassed by using another string variable.
I'm sure there's a way to simplify things using structs or creating a new function or something, but I haven't gotten into those yet.
The Global String Variables are Action, Action2, and ObjectName.
Here's sample code for the display GUI. You could use the default one and just change the name. Put this in the Global script.
Code: ags
function repeatedly_execute() 
{
  lblNewAction.Text = String.Format("%s %s %s", Action, location,  Action2);
  }


Here's sample code for one of the buttons.
Code: ags

function Button1_OnClick(GUIControl *control, MouseButton button)
{
Action = "Push";
Action2 = "Left";
}

And here's sample code for an object.

Code: ags
    
  if ((Action == "Push") && (Action2 == "Left") && (ObjectName== "TV"))
  {
    oTV.Move(oTV.X - 20, oTV.Y, 10, eNoBlock, eAnywhere);
      Action = "";
      Action2 = "";
      ObjectName="";
     gVerbs.Visible=false;
  }
else if ((Action == "Push") && (Action2 == "Down") && (ObjectName== "TV"))
  {
    oTV.Move(oTV.X, oTV.Y + 20, 10, eNoBlock, eAnywhere);
    Action = "";
    Action2 = "";
    ObjectName="";
    gVerbs.Visible=false;
  }
  else
  {
gVerbs.X = mouse.x;
gVerbs.Y = mouse.y;
gVerbs.Visible=true;
ObjectName="TV";
  }


PaulineV

Quote from: VampireWombat on Wed 22/05/2019 13:02:44
Oops. I meant click on the object again. And actually, that part can be bypassed by using another string variable.
I'm sure there's a way to simplify things using structs or creating a new function or something, but I haven't gotten into those yet.
The Global String Variables are Action, Action2, and ObjectName.
Here's sample code for the display GUI. You could use the default one and just change the name.

Wow, thank you very much for your help !
I will try that approach and to adapt it to my game. If I find something to simplify it, I'll let you know !

VampireWombat

#7
You're welcome and good luck. My coding is probably bad enough to make a programmer cry. But it should accomplish what you seem to want.

Edit: I just remembered why I always had to click the object a second time. To be able to only click it once and then click the verb using this method would require putting the object code under the Verb buttons in the Global Script.

Here's a revised version. It only uses one Int variable, ObjectNumber. The downside to it is that it does the same thing to any object in any room with the number...

Here's a sample button.
Code: ags
function Button1_OnClick(GUIControl *control, MouseButton button)
{
if (ObjectNumber== 0){
      object[0].Move(object[0].X,  object[0].Y - 2, 1, eBlock, eAnywhere);
      ObjectNumber=0;
      gVerbs.Visible=false;
      }
}


And here's the code for the object.
Code: ags
function oTV_Interact()
{
gVerbs.X = mouse.x;
gVerbs.Y = mouse.y;
gVerbs.Visible=true;
ObjectNumber=0;
}


edit again:  Adding another Global int of RoomNumber can help with one of the issues. You'd have to change the variable whenever changing rooms, of course.

Modified code.

Code: ags
function Button1_OnClick(GUIControl *control, MouseButton button)
{
if ((ObjectNumber== 0) && (RoomNumber== 1)){ // Very first object in the first room.
      object[0].Move(object[0].X,  object[0].Y - 2, 1, eBlock, eAnywhere);
      }
else if ((ObjectNumber== 0) && (RoomNumber== 2)){ // Very first object in the second room.
      player.Say("No thanks.");
      }
else if ((ObjectNumber== 1) && (RoomNumber== 1)){ // Second object in the first room.
      player.Say("I shouldn't do that.");
      }
else { // All other objects.
      player.Say("I don't want to move that."); 
      } 
      ObjectNumber=0; // Resets the object number every time.
      gVerbs.Visible=false; // Hides the gui every time.
}

PaulineV

Quote from: VampireWombat on Wed 22/05/2019 13:18:19
You're welcome and good luck. My coding is probably bad enough to make a programmer cry. But it should accomplish what you seem to want.

Edit: I just remembered why I always had to click the object a second time. To be able to only click it once and then click the verb using this method would require putting the object code under the Verb buttons in the Global Script.

Here's a revised version. It only uses one Int variable, ObjectNumber. The downside to it is that it does the same thing to any object in any room with the number...

Hi VampireWombat !
I tried your code and it is working quite exactly like I wanted. Thank you very much !
I used only one globale variable object_selected, as a String and I do :

Code: ags

function oTV_Interact()
{
gVerbs.X = mouse.x;
gVerbs.Y = mouse.y;
gVerbs.Visible=true;
object_selected= "TV";
}


Then you only have to check this variable in the Button1_OnClick function. I agree that there is probably a more efficient way to do it but for now it will do the trick !
By any chance, do you know if it possible to prevent any player action (click on another object, on hotspot or just walk) while the GUI is opened ?

VampireWombat

Oh, right. I don't know why I didn't think of that. Glad to hear it works as wanted.

And I'm sure there is, but I can't think of it at the moment. Until someone can give you a better solution, you could create a 2nd GUI that opens at the same time that covers the whole screen and has like 1% opacity.
You'll need to adjust the Z order of the GUIs to make sure that the verb gui is on top.

PaulineV

Right, that's smart :)
I leave the topic opened, maybe someone will have some coding solution too.

SMF spam blocked by CleanTalk