adding a verb to change character

Started by Jojowl80, Sat 21/11/2020 04:48:21

Previous topic - Next topic

Jojowl80

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!

Crimson Wizard

#1
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

if (player == cCharacter1)
    cCharacter2.SetAsPlayer();
else if (player == cCharacter2)
    cCharacter3.SetAsPlayer();
else
    cCharacter1.SetAsPlayer();

Jojowl80

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

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.

Crimson Wizard

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?

Jojowl80

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

#6
(Expand spoiler to reveal picture)
Spoiler
[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.

Jojowl80

for all 9 buttons it says OnClick     Action_click    ...

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

Crimson Wizard

#8
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)

Jojowl80

Awesome got it working!. Crimson you understood me the whole time, sorry I am just a little slow. Thanks everyone for the help!

SMF spam blocked by CleanTalk