Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Jojowl80 on Sat 21/11/2020 04:48:21

Title: adding a verb to change character
Post by: Jojowl80 on Sat 21/11/2020 04:48:21
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!
Title: Re: adding a verb to change character
Post by: Crimson Wizard on Sat 21/11/2020 05:48:59
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 (ags) Select

if (player == cCharacter1)
    cCharacter2.SetAsPlayer();
else if (player == cCharacter2)
    cCharacter3.SetAsPlayer();
else
    cCharacter1.SetAsPlayer();
Title: Re: adding a verb to change character
Post by: Jojowl80 on Sat 21/11/2020 17:42:25
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 ^_^
Title: Re: adding a verb to change character
Post by: eri0o on Sat 21/11/2020 17:48:45
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.
Title: Re: adding a verb to change character
Post by: Crimson Wizard on Sat 21/11/2020 17:57:22
Quote from: Jojowl80 on Sat 21/11/2020 17:42:25
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?
Title: Re: adding a verb to change character
Post by: Jojowl80 on Sat 21/11/2020 18:46:37
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.
Title: Re: adding a verb to change character
Post by: eri0o on Sat 21/11/2020 19:08:50
(Expand spoiler to reveal picture)
Spoiler
(https://i.imgur.com/z6cQxz2.png)
[close]

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.
Title: Re: adding a verb to change character
Post by: Jojowl80 on Sat 21/11/2020 19:17:38
for all 9 buttons it says OnClick     Action_click    ...

so are you saying I can create my own function there?
Title: Re: adding a verb to change character
Post by: Crimson Wizard on Sat 21/11/2020 19:19:05
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)
Title: Re: adding a verb to change character
Post by: Jojowl80 on Sat 21/11/2020 19:26:10
Awesome got it working!. Crimson you understood me the whole time, sorry I am just a little slow. Thanks everyone for the help!