Choosing/Changing Characters
lizzytypeperson
03 Dec 2016, 00:06Hey, so, I've gone through the tutorial and I've been working on this game pretty successfully so far but I just can't wrap my head around one thing that I feel is probably pretty simple. At the start of my game, I'd like for the player to select one of three characters to play as and I just kind of don't understand how to do that.
Additionally, I wanted to see if I could make the player able to switch between the characters at will, and I know there's a thing about scripting that somewhere online. I have read it but it says it's obsolete because that's a function that's just programmed into the latest versions of Quest. Except I don't know how to make that work. Like, I have the character objects set to be things the player can turn into, but I don't know how to make it work in-game. The command for it, I guess. Or if I need to make a command for it.
Any help would be greatly appreciated!!
XanMag
03 Dec 2016, 00:58This is an explanation from my tutorial game that is hiding in some dark recesses of Quests game bank! It needs some user friendliness added but I like to refer to it when I run into problems, so here is code from my switching POV rooms.
You can skip down to the bottom if you don't want to mess with the code below
<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>
<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 = player) {
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="switch to magoo cmd">
<pattern>switch to magoo; switch to Magoo; switch to mag; switch to Mag</pattern>
<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 (player)
}
else {
msg ("You already are Magoo, dork.")
}
]]></script>
I know this only answers part of your question. I'll look at the other part of it. You do need to tick the box that makes it possible for the object to become a player object under the feature tabs. You need a global command if you want to be able to switch players from any location in the game.
Quite easy after all... all you need to do is choose the change player object script and it will move you into the room that the player is in. Pretty simple after all.
So...
- Create all of your character objects by adding each object and tick the player can become object box under features.
2a. Create a global command and type --> change characters; change player; --> any command you want the player to type to be able to change players. Note - if you have multiple characters you can switch to, you will want to add a command for each character object --> change to Fred AND change to Frank AND change to FIDO, etc... I'm sure there might be a fancy command string you can type in the box that can account for change to (whomever) and run a bunch of else if's but I think this is easier.
2b. If you want to change characters when only in certain room, place the command in the room and not in the game object in the tree.
2c. If you want to change characters when only in the same room, place an IF in there to check and see if the player you want to change to is in the same room as the player.
I have a small bit of sample code if you need to see a simpler switch in action
Let me know if this answers your questions! Good luck!
hegemonkhan
03 Dec 2016, 07:35the 'pov' system documentation/links:
http://docs.textadventures.co.uk/quest/tutorial/changing_the_player_object.html
http://docs.textadventures.co.uk/quest/functions/corelibrary/changepov.html
http://docs.textadventures.co.uk/quest/upgrade_notes.html (see the link for the 5.3 beta game release, it is when the 'pov' system was added to quest)
https://blog.textadventures.co.uk/2012/12/03/quest-5-3-beta-is-now-available/ ( scroll down to 'game change' section: see the 'changeable pov' content )
https://blog.textadventures.co.uk/2012/09/19/pov-support-multiple-player-objects-in-quest-5-3/
the 'pov' system:
prior (v5.2- / 520-) to quest version 5.3+ (530+), there was a single Player Object only, but now we can have multiple Player Objects, which we can switch the current control of for the person playing the game. This current-control is done via the 'pov' (point of view) Object Attribute contained within the 'game' Game (global settings and etc) Object. This 'game.pov' stores/saves and is/determines the currently controlled Player Object, an example in code:
<game name="example_game">
<attr name="pov" type="object">player</attr> // this is your initially controlled Player Object
</game>
<object name="room">
</object>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="feature_player" type="boolean">true</attr> // it's shortened form is this: <feature_player /> // when you check for the Object to be '[can be player object]' in the GUI/Editor, this is the code line (it's the built-in 'feature_player' Boolean Attribute with it's Value as 'true' ) that makes the Object a Player Object, or in-code, you can also add the '<inherit name="editor_object" />' and must also add too: '<inherit name="editor_player" />', which will also make your Object a Player Object too
<attr name="parent" type="object">room</attr>
</object>
<object name="HK">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="feature_player" type="boolean">true</attr>
<attr name="parent" type="object">room</attr>
</object>
<object name="lizzytypeperson">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="feature_player" type="boolean">true</attr>
<attr name="parent" type="object">room</attr>
</object>
// ------
and you can set/re-set/change who you're currently controlling in scripting, via:
run as script -> add new attribute -> 'variables' section/category -> 'set a variable or attribute' Script -> (see below)
set variable NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = [EXPRESSION] VALUE_OR_EXPRESSION
examples:
set variable game.pov = [EXPRESSION] player // the currently controlled Player Object is the 'player' Player Object
set variable game.pov = [EXPRESSION] HK // the currently controlled Player Object is the 'HK' Player Object
set variable game.pov = [EXPRESSION] lizzytypeperson // the currently controlled Player Object is the 'lizzytypeperson' Player Object
or directly in code, as:
game.pov = player // the currently controlled Player Object is the 'player' Player Object
game.pov = HK // the currently controlled Player Object is the 'HK' Player Object
game.pov = lizzytypeperson // the currently controlled Player Object is the 'lizzytypeperson' Player Object
or, you can use the 'ChangePov' Script/Function:
ChangePov (player)
ChangePov (HK)
ChangePov (lizzytypeperson)
// -----------
In the GUI/Editor:
run as script -> add new script -> 'Objects' section/category -> 'Change player object' script option // I think this is the same as the 'ChangePov' Function shown above
conceptually, this is what you want to do:
- create/add 3 Objects to be your 3 Player Objects, make sure you set them as 'can be Player Objects', which is done like this:
'whatever' Object -> 'Features' Tab -> check in (or make sure it is checked in) the 'Player: player can become this object' box
'whatever' Object -> 'Player' Tab -> Player: [Can be a player] // make sure it is on this option
Also, on the 'game' Game (global settings and etc) Object, you can set what Player Object is your initial/starting current Player Object (it doesn't matter if you do this as at game start you're going to be choosing which Player Object to start as anyways --- which will over-ride your initially setted Player Object, so you might as well do so, to avoid any possible issues that may come up if you don't):
'game' Game (global settings and etc) Object -> 'Player' Tab -> Player Object: [PLAYER_OBJECT_THAT_YOU_WANT_TO_INITIALLY_START_AS]
- create the menu at the start of the game to select your initial/starting Player Object:
the built-in 'start' Script Attribute contained within the 'game' Game (global settings and etc) Object is the first thing that is done at the start of the game:
'game' Game (global settings and etc) Object -> 'Scripts' Tab -> 'start' Script -> (see below)
add new script -> 'output' section/category -> 'Show a menu' Script -> (see below)
Show menu with caption [text]: YOUR_PROMPT/QUESTION
Options from list/dictionary: game.pov_objectlist_attribute
Allow player to ignore menu: [no]
After choosing, run script: (see below)
add new script -> 'Objects' section/category -> 'change player object' -> (see below)
change player object to [expression] result // or if just the 'result' doesn't work, then try typing in this instead: GetObject (result)
- we need to now actually create/add our 'pov_objectlist_attribute' Objectlist Attribute contained within the 'game' Game (global settings and etc) Object (as the menu in #2, can't use an Objectlist Attribute that doesn't exist):
(unfortunately, this can't be done in the GUI/Editor --- well maybe it can be with scripting, but let's just code it in directly, to be safe)
at the very top of the screen, there's a horizontal menu bar, find the notepaper-like button between the 'play' and 'help' buttons, Click on this notepaper-like button, as it's a toggle between the GUI/Editor view mode and for this top horizontal menu bar notepaper-like button its the full/entire game code Code View mode. Now that you're looking at the GUI/Editor's code view of your entire/full game code, find this 'creation' tag block:
<game name="NAME_OF_YOUR_GAME">
// various content: Attributes (author, version, firstpublished, start, etc etc etc)
</game>
and we want to type/add in this 'creation' tag line/block, so it looks like this:
<game name="NAME_OF_YOUR_GAME">
// various content: Attributes (author, version, firstpublished, start, etc etc etc)
<attr name="pov_objectlist_attribute" type="objectlist">NAME_OF_PLAYER_OBJECT_1;NAME_OF_PLAYER_OBJECT_2;NAME_OF_PLAYER_OBJECT_3</attr>
</game>
note that in #2, for the menu creation, we added/typed in: game.pov_objectlist_attribute, do you see how it matches up to the above? NAME_OF_CONTAINING_OBJECT.NAME_OF_ITS_CONTAINED_ATTRIBUTE: game.pov_objectlist_attribute, just so you can understand coding and its matchup to using the GUI/Editor stuff. The '' tag block is the same as in the GUI/Editor: the 'game' Game Object -> its various Tabs for adding Attributes and whatever else
- create a Command to be able to type in a command during game play, to change your Player Objects (or let me know if you want to have a different game design on how/when/where you switch amongst your Player Objects), an example:
Objects -> game -> Commands -> Add -> (see below)
'Command' Tab:
Pattern: [Command pattern]
text box: cp
// 'cp' for 'change pov', this (cp) is what you type in during game play, to change amongst your Player Objects
Name: change_pov_command
Unresolved Object text: Failed to change your pov
Script: (see below, it's the same as what you did in #2)
add new script -> 'output' section/category -> 'Show a menu' Script -> (see below)
Show menu with caption [text]: YOUR_PROMPT/QUESTION
Options from list/dictionary: game.pov_objectlist_attribute
Allow player to ignore menu: [no]
After choosing, run script: (see below)
add new script -> 'Objects' section/category -> 'change player object' -> (see below)
change player object to [expression] result // or if just the 'result' doesn't work, then try typing in this instead: GetObject (result)
- I should have shown you in putting our menu scripting block into a Function... but whatever... meh. If you use the menu scripting block a lot, let me know, and I'll help show you how to put it into a Function, and how to use Functions, to make it easier for you. Or... we could just run the 'game.start' Script Attribute... to re-use the change pov menu... meh, whatever.