A Little Guidance on Multiple Player Objects

jaybug_jimmies
Hi!

I used to use Quest to create games years ago. I've recently jumped back into things and am re-learning the new version and reading all the tutorials. I was hoping for a little guidance for a newbie.

The game I'd like to create would have two characters working together as partners to solve puzzles. I want the player to be able to play as either one of these characters and be free to switch back and forth between Character A and Character B. Character A would have different printed texts when looking at or trying to pick up various objects in the environment than Character B has. (E.g., Mary looks at a TV and the text prints 'I love this show,' Bob looks at the same TV and text prints 'This show is terrible.') Furthermore, both Characters A and B will follow one another as they move from room to room, solving puzzles.

My question is, what's the easiest way to go about accomplishing this? (I am not yet experienced enough to work with 'deeper' stuff like writing the code by hand from scratch.)

Thank you so much,

-Heather

EDIT: I should note my current plan as it stands is to make a Character A and B object for every single room (Character A #1, #2, #3, etc.) and then create a global custom Command 'switch to character B' and then a huge list of "If player is object [characterA#1] then switch player object to [characterB#1] and make [CharacterB#2, 3, 4, 5 . . . ] invisible." Hopefully that brief explanation makes sense. But yeah, that method seems awfully time-consuming.

TinFoilMkIV
So the first trick that will likely be very helpful here, is knowing that game.pov always refers to the player controlled character. So regardless of whether you control Character A or Character B, game.pov will be equal to the one you are in control of.

The really useful part is how you can pull attributes using this reference. For example, game.pov.alias will give you the alias of the character you're in control of, and game.pov.parent will give you the room or object the player is directly inside.

Making use of this you can create scripts that can check what character you're currently in control of and give the proper output. another piece of info that can help a lot with multiple player characters, is that you can set object and room descriptions as scripts, and not just text. In the setup tab of an object, at the bottom is a description section, there is a drop down menu to select either 'no description', 'text', or 'run script', you'll want the 'run script' option for this. So then as follows you can simply use an If/else script to setup different responses per character.

Under 'add new script', you want to scroll down to the 'Scripts' section, and 'If...' should be the second option. For the expression on your 'If', you will probably want something like 'game.pov.name = CharacterA', then you use messages to create the text output for that character, and repeat for any extra characters you want with special reactions. In this case if you stick to only two characters then you only need to specify CharacterA for the first response, and CharacterB will just be the 'Else' section, since if you aren't in control of CharacterA you must be in control of CharacterB.

Also some possibly relevant info about changing the player character

So Now that you can script descriptions and such individually for your characters, we can work on cleaning up your actual character objects, so that you won't need 9001 copies of them lying around.

Basically you want to set up a script that whenever you enter a new room, your following character will then be placed in that same room. Fortunately it's not actually that difficult to setup. Earlier I mentioned game.pov.parent, this is important because the room you are currently in is the player objects parent. Since the player is not always the same character we will want to use the game.pov reference to make sure we are always following the actual player. Fortunately for us, the 'game' object has a built in script section for when you enter a room, it's under the 'script' tab and even listed as 'script when entering a room'

Since we don't want the player to accidentally end up 'following' a stationary npc and getting dragged back to the same room constantly, you will want to use an 'If' statement again to specify which character is doing the following. Then from there you just use 'CharacterB.parent = game.pov.parent' and your CharacterB will then 'follow' your player. And of course when playing CharacterB you will instead have CharacterA follow the player.

And here's a section from the quest guides about following the player.

XanMag
My current (and nearly completed...) second game has a very similar format. Two characters work together to solve problems the other cannot. I put a command in the game something like "switch places with David". Then I added a switch player object to David script. And...voila! My controlled player is now the next player.

The code from my tutorial is placed in the response below.

XanMag
This is a copy-paste job from the tutorial game I am working on. If you copy-paste the code below into a new game, you should be able to see how I switched players once you view it in the GUI of Quest. If something doesn't make sense, please ask or point out any mistakes to me. It will help me better my tutorial. Thanks!

  <object name="changing player object room">
<inherit name="editor_room" />
<description><![CDATA[<br/>You are in a changing player object room. If you want to give it a shot, simply type either "switch to magoo" or "switch to xanadu" to see what happens.<br/><br/>Also, there is a ladder here that leads up to the 'changing room'. Try taking your controlled character up there and type the switch commands mentioned above. <br/><br/>For more of an explanation of how this switching of characters works, type 'explain switch'.]]></description>
<object name="Xanadu">
<inherit name="editor_object" />
<inherit name="namedmale" />
<look type="script">
if (game.pov = Magoo) {
msg ("Holy moly! That looks exactly like you! To take control of Xanadu, just type 'switch to Xanadu'.")
}
else {
msg ("You are the new you. You are Xanadu. You look exactly like your former self. Nerdy and ugly!")
}
</look>
</object>
<command name="switch to xan cmd">
<pattern>switch to xanadu; switch to Xanadu; switch to xan; switch to Xan</pattern>
<script><![CDATA[
if (game.pov = Magoo) {
msg ("You close your eyes and grunt real hard. When you open them...<br/>")
wait {
msg ("<br/>You feel different, but oddly look quite similar. You have switched places with Xanadu, your alter ego. To change back to Magoo, simply type 'switch to magoo'.<br/>")
}
ChangePOV (Xanadu)
}
else {
msg ("Ummm... you already are Xanadu.")
}
]]></script>
</command>
<object name="Magoo">
<inherit name="editor_object" />
<inherit name="editor_player" />
<inherit name="namedmale" />
<look type="script">
if (game.pov = Xanadu) {
msg ("Holy moly! That looks exactly like you! To take control of Magoo, just type 'switch to Magoo'.")
}
else {
msg ("You are a simple being trapped in a test game.")
}
</look>
<attr name="pov_look">You're Magoo. A simple being trapped in a test game.</attr>
</object>
<command name="switch to magoo cmd">
<script><![CDATA[
if (game.pov = Xanadu) {
msg ("<br/>You close your eyes and grunt real hard. When you open them...<br/>")
wait {
msg ("<br/>You feel different, but oddly look quite similar. You have switched places with Xanadu, your alter ego. To change back to xanadu, simply type 'switch to xanadu'.<br/>")
}
ChangePOV (Magoo)
}
else {
msg ("You already are Magoo, dork.")
}
]]></script>
<pattern>switch to magoo; switch to Magoo; switch to mag; switch to Mag</pattern>
</command>
<object name="changing room">
<inherit name="editor_room" />
<description><![CDATA[You are in a changing room. Try to "switch to magoo" or "switch to xanadu" from here to see what happens.<br/><br/>For more of an explanation of how this switching of characters works, type 'explain switch'.]]></description>
<exit alias="down" to="changing player object room">
<inherit name="downdirection" />
</exit>
<command name="switch to magoo cmd1">
<script><![CDATA[
if (game.pov = Xanadu) {
msg ("<br/>You close your eyes and grunt real hard. When you open them...<br/>")
wait {
msg ("<br/>You feel different, but oddly look quite similar. You have switched places with Xanadu, your alter ego. To change back to xanadu, simply type 'switch to xanadu'.<br/>")
}
ChangePOV (Magoo)
}
else {
msg ("You already are Magoo, dork.")
}
]]></script>
<pattern>switch to magoo; switch to Magoo; switch to mag; switch to Mag</pattern>
</command>
<command name="switch to xan cmd1">
<pattern>switch to xanadu; switch to Xanadu; switch to xan; switch to Xan</pattern>
<script><![CDATA[
if (game.pov = Magoo) {
msg ("You close your eyes and grunt real hard. When you open them...<br/>")
wait {
msg ("<br/>You feel different, but oddly look quite similar. You have switched places with Xanadu, your alter ego. To change back to Magoo, simply type 'switch to magoo'.<br/>")
}
ChangePOV (Xanadu)
}
else {
msg ("Ummm... you already are Xanadu.")
}
]]></script>
</command>
<command name="explain switch cmd">
<pattern>explain switch</pattern>
<script><![CDATA[
msg ("To keep the switch from happening in other rooms within this tutorial, I have placed the commands 'switch to xan' and 'switch to magoo' in only the \"changing player object room\" and the \"changing room\". To make the characters switchable from any room in your game, you would put the command to switch under the room/objects tree on the left side of the GUI editor. <br/><br/>If you only want the characters to be able to switch when they are in the same room, insert an 'If/Then' script to check to see if the other controllable character is in the room, then use the change player object script. Of course, you should add an 'Else' to that script to let the player know that the switch is not allowable at this time or location using a print message script. Or, on a similar note, if you want the players to only be able to switch when they are in certain rooms, you can add 'If/Then/Else' scripts to check to see if that object is in the room or you can raise flags and check your if against a flag.")
]]></script>
</command>
</object>
<exit alias="up" to="changing room">
<inherit name="updirection" />
</exit>
<command name="explain switch cmd1">
<pattern>explain switch</pattern>
<script><![CDATA[
msg ("To keep the switch from happening in other rooms within this tutorial, I have placed the commands 'switch to xan' and 'switch to magoo' in only the \"changing player object room\" and the \"changing room\". To make the characters switchable from any room in your game, you would put the command to switch under the room/objects tree on the left side of the GUI editor. <br/><br/>If you only want the characters to be able to switch when they are in the same room, insert an 'If/Then' script to check to see if the other controllable character is in the room, then use the change player object script. Of course, you should add an 'Else' to that script to let the player know that the switch is not allowable at this time or location using a print message script. Or, on a similar note, if you want the players to only be able to switch when they are in certain rooms, you can add 'If/Then/Else' scripts to check to see if that object is in the room or you can raise flags and check your if against a flag.")
]]></script>
</command>
</object>

jaybug_jimmies
Oh, awesome! Thank you both so much. I'm gonna study these and get to work! I'll let you know how it turns out.

-Heather

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums