Author Topic: adding a verb to change character  (Read 223 times)

adding a verb to change character
« on: 21 Nov 2020, 04:48 »
hey I have searched relentlessy on how to change a character using verbs, to no avail. I have 3 characters in the game and I would like to be able to switch through them in order, by using one button. I made a button for the GUI already I just don't know how to connect it to the main script.  thanks!

Re: adding a verb to change character
« Reply #1 on: 21 Nov 2020, 05:48 »
This is not really a verb, just a button ("verb" has specific meaning in AGS), but that's not very important.

First of all you need to connect button event to script. Select button in the editor, look at its properties, switch to events ("lightning" tool button), and double click on "OnClick" event, that will create a script function and bind it to this event.

Inside that function write your code which changes character. Switching itself is done simply as "cCharacter.SetAsPlayer();" (where cCharacter is your character's script name).

Switching 3 characters in certain order can be done by something as simple as:
Code: Adventure Game Studio
  1. if (player == cCharacter1)
  2.     cCharacter2.SetAsPlayer();
  3. else if (player == cCharacter2)
  4.     cCharacter3.SetAsPlayer();
  5. else
  6.     cCharacter1.SetAsPlayer();
  7.  
« Last Edit: 21 Nov 2020, 05:51 by Crimson Wizard »

Re: adding a verb to change character
« Reply #2 on: 21 Nov 2020, 17:42 »
What I am saying is I have a 9th button made and fit into the rest of the Verbs, its a change character button. when I press it I get the error *could not find the action corresponding with this button* which makes perfect sense. It takes me to GetButtonAction in VerbGui. my question is what do I need to put in there. Sorry if I suck at making myself clear ^_^

eri0o

Re: adding a verb to change character
« Reply #3 on: 21 Nov 2020, 17:48 »
I have absolutely no idea what you are talking about now. Can you explain again with screenshots of what you mean in the ags editor? My guess is it's something really specific to some template and it would be helpful to also mention which template you are using.

Re: adding a verb to change character
« Reply #4 on: 21 Nov 2020, 17:57 »
What I am saying is I have a 9th button made and fit into the rest of the Verbs, its a change character button. when I press it I get the error *could not find the action corresponding with this button* which makes perfect sense. It takes me to GetButtonAction in VerbGui. my question is what do I need to put in there. Sorry if I suck at making myself clear ^_^

I am not complete sure, but it sounds like you may have connected the new button to existing template function somehow. Have you checked its events, is OnClick event filled? Have you tried connecting it to your own function?

Re: adding a verb to change character
« Reply #5 on: 21 Nov 2020, 18:46 »
sorry I am using tumbleweed template.  8 of the verbs are already used, *open* *close* *look at*. etc. I made a new button to change characters when clicked, into the GUI: gMain. Now when I hit *open* for example it calls on either the global script or the verbgui to use the *open* verb. So my question is what do I have to put in there to call that function for *Change Character* when that button is clicked. Sorry if that still doesnt make sense. I either cant take screenshots or find where they are.

eri0o

Re: adding a verb to change character
« Reply #6 on: 21 Nov 2020, 19:08 »
(Expand spoiler to reveal picture)
Spoiler: ShowHide


In the properties menu at left (in this picture, yours may be elsewhere), with the button selected in the GUI editor, after clicking the lighting bolt icon, what function is written there between OnClick and the button with three dots? If it's empty you have to connect this with your function.
« Last Edit: 21 Nov 2020, 19:10 by eri0o »

Re: adding a verb to change character
« Reply #7 on: 21 Nov 2020, 19:17 »
for all 9 buttons it says OnClick     Action_click    ...

so are you saying I can create my own function there?

Re: adding a verb to change character
« Reply #8 on: 21 Nov 2020, 19:19 »
Yes, remove "Action_click" for your 9th button, then click on "...", and it will create your own function in global script.

Then use the example of the code I posted in my first reply above to make characters switch.

(Also, when you create new buttons on GUI, you may simply double click on them to create OnClick function for them)
« Last Edit: 21 Nov 2020, 19:25 by Crimson Wizard »

Re: adding a verb to change character
« Reply #9 on: 21 Nov 2020, 19:26 »
Awesome got it working!. Crimson you understood me the whole time, sorry I am just a little slow. Thanks everyone for the help!