Unknown object or variable 'player'
Siljestam
20 Feb 2016, 04:11I want to have a Custom Player Status called "Condition" which is set to "Human" at the start of the game.
When Health drops to 0 I want to change that Status to "Zombie", but when I enter Set variable player.condition = "Zombie" the game gives me the following error message:
Error running script: Error compiling expression 'player': Unknown object or variable 'player'
How do I change a Player object status attribute?
Thanks!
When Health drops to 0 I want to change that Status to "Zombie", but when I enter Set variable player.condition = "Zombie" the game gives me the following error message:
Error running script: Error compiling expression 'player': Unknown object or variable 'player'
How do I change a Player object status attribute?
Thanks!
HegemonKhan
20 Feb 2016, 05:12an example (I'm using the default 'player' as the Player Object's 'name' Attribute for this example, if you renamed it, then just replace 'player' with whatever you renamed it as):
(quest is case sensitive, 'condition' and 'Condition' are seen by quest as two completely different Attributes, make sure your Objects' and Attributes' are correct throughout what you do in your game, also, this means you got to make sure you spelled everything correctly/matches up, no typos in coding!)
(also, I don't like upper case, so my example will use all lowercase)
----------
Create the Attribute:
'player' Player Object -> 'Attributes' Tab -> Attributes -> add -> (see below)
(Object Name: player)
Attribute Name: condition
Attribute Type: string
Attribute Value: "human"
in code it looks like this:
--------
next let's create the Status Attribute (this is merely for displaying your Attributes on the right side, in the 'status' pane, during game play. You can't display what doesn't exist, you need to actually create the Attribute, the 'Status Attribute' doesn't create Attributes, it just displays them):
'player' Player Object -> 'Attributes' Tab -> Status Attributes -> add -> (see below)
Attribute Name: condition
Attribute Field (Value), type this in* exactly: Condition: !
------
and while we're at it... let's also get it to display your 'health' too:
'player' Player Object -> 'Attributes' Tab -> Status Attributes -> add -> (see below)
Attribute Name: health
Attribute Field (Value), type this in* exactly: Health: !
----
the '!' is a special command-character-symbol which tells quest to replace it with whatever your 'condition' Attribute's value is currently
*It'll output (display/look like) this in the status pane during game play:
Condition: (human/zombie/etc, whatever your current condition is)
if you don't like this, let me know and I can help you if you need help with having it output differently
this is how it looks in code:
------
lastly, your scripting for changing your 'condition' Attribute's Value to 'zombie' when your life reaches 0:
'player' Player Object -> 'verb' Tab -> add -> (see below)
Verb Name: changedhealth
Verb Script: (see below, too lazy to show via using GUI~Editor, so only showing it in code)
------------
if you want to look at my guide on using Attributes, Status Attributes, and the 'if' Script, here it is:
viewtopic.php?f=18&t=5559
but it is more code focused... but I do think I show how to do it in the GUI~Editor too
(quest is case sensitive, 'condition' and 'Condition' are seen by quest as two completely different Attributes, make sure your Objects' and Attributes' are correct throughout what you do in your game, also, this means you got to make sure you spelled everything correctly/matches up, no typos in coding!)
(also, I don't like upper case, so my example will use all lowercase)
----------
Create the Attribute:
'player' Player Object -> 'Attributes' Tab -> Attributes -> add -> (see below)
(Object Name: player)
Attribute Name: condition
Attribute Type: string
Attribute Value: "human"
in code it looks like this:
<object name="player">
<attr name="condition" type="string">human</attr>
// or it's shortened syntax version (for String Attributes only):
// <condition>human</condition>
</object>
--------
next let's create the Status Attribute (this is merely for displaying your Attributes on the right side, in the 'status' pane, during game play. You can't display what doesn't exist, you need to actually create the Attribute, the 'Status Attribute' doesn't create Attributes, it just displays them):
'player' Player Object -> 'Attributes' Tab -> Status Attributes -> add -> (see below)
Attribute Name: condition
Attribute Field (Value), type this in* exactly: Condition: !
------
and while we're at it... let's also get it to display your 'health' too:
'player' Player Object -> 'Attributes' Tab -> Status Attributes -> add -> (see below)
Attribute Name: health
Attribute Field (Value), type this in* exactly: Health: !
----
the '!' is a special command-character-symbol which tells quest to replace it with whatever your 'condition' Attribute's value is currently
*It'll output (display/look like) this in the status pane during game play:
Condition: (human/zombie/etc, whatever your current condition is)
if you don't like this, let me know and I can help you if you need help with having it output differently
this is how it looks in code:
<object name="player">
<attr name="condition" type="string">human</attr>
<attr name="statusattributes" type="simplestringdictionary">health = Health: !; condition = Condition: !</attr>
</object>
------
lastly, your scripting for changing your 'condition' Attribute's Value to 'zombie' when your life reaches 0:
'player' Player Object -> 'verb' Tab -> add -> (see below)
Verb Name: changedhealth
Verb Script: (see below, too lazy to show via using GUI~Editor, so only showing it in code)
<object name="player">
<attr name="condition" type="string">human</attr>
<attr name="statusattributes" type="simplestringdictionary">health = Health: !; condition = Condition: !</attr>
<attr name="changedhealth" type="script">
<![CDATA[
if (player.health <= 0 and player.condition <> "zombie") {
player.condition = "zombie"
}
]]>
</attr>
</object>
------------
if you want to look at my guide on using Attributes, Status Attributes, and the 'if' Script, here it is:
viewtopic.php?f=18&t=5559
but it is more code focused... but I do think I show how to do it in the GUI~Editor too
Siljestam
20 Feb 2016, 05:39So far I don't write in code, I just use the editor so unfortunately this isn't of much help...
If you can make this work in the editor and show me how you did it, I would be grateful.
If you can make this work in the editor and show me how you did it, I would be grateful.
HegemonKhan
20 Feb 2016, 05:54To help you, we need to know what you did in more specific detail, so we can see what needs to be changed/fixed up for it to work.
the easiest way (if you don't mind making your game code public), is to post your game code (hopefully it's not too big a game yet, it's easier to troubleshoot a smaller game obviously: less code lines), which you can do two ways to get into/see your entire game code:
1. just right click on your 'xxx.aslx' game file, and open it up using a text software (notepad, wordpad, notepad++, apple: text editor, etc). highlight the entire file's contents (this is your entire game code), and copy it, then past it into a post here, like this:
[code.]paste your game code here[/code.]
but without the dots/periods in the 'code' brackets, which will produce the code box, see below:
2. within the GUI~Editor, at the top of the screen, is a menu bar, find the notepaper like button (it's between the 'play' and '?-help' buttons). This is a toggle button to go between the GUI~Editor mode and 'Code View' mode. The 'Code View' mode, is your entire game code. So, click on it, to go into Code View mode (save your game file if you haven't already), highlight the entire contents (this is your entire game code), copy it, and paste it here, as explained up above in #1.
------
if you don't want to make your game code public, you can pm it to me or one of the moderators, and we'll fix up your code for you, keeping it private.
-------
otherwise, you're going to have to describe/explain in more detail or specifically what you've done, so we can figure out what the issue is, so we can then fix it (and/or explain how to do it correctly) for you.
the easiest way (if you don't mind making your game code public), is to post your game code (hopefully it's not too big a game yet, it's easier to troubleshoot a smaller game obviously: less code lines), which you can do two ways to get into/see your entire game code:
1. just right click on your 'xxx.aslx' game file, and open it up using a text software (notepad, wordpad, notepad++, apple: text editor, etc). highlight the entire file's contents (this is your entire game code), and copy it, then past it into a post here, like this:
[code.]paste your game code here[/code.]
but without the dots/periods in the 'code' brackets, which will produce the code box, see below:
paste your game code here
2. within the GUI~Editor, at the top of the screen, is a menu bar, find the notepaper like button (it's between the 'play' and '?-help' buttons). This is a toggle button to go between the GUI~Editor mode and 'Code View' mode. The 'Code View' mode, is your entire game code. So, click on it, to go into Code View mode (save your game file if you haven't already), highlight the entire contents (this is your entire game code), copy it, and paste it here, as explained up above in #1.
------
if you don't want to make your game code public, you can pm it to me or one of the moderators, and we'll fix up your code for you, keeping it private.
-------
otherwise, you're going to have to describe/explain in more detail or specifically what you've done, so we can figure out what the issue is, so we can then fix it (and/or explain how to do it correctly) for you.
Siljestam
20 Feb 2016, 06:08I have just gotten started, so hopefully the game code doesn't take up too much space 
There may be a few loose ends beyond the one mentioned in the topic, but that's the main one I want to learn how to deal with.

There may be a few loose ends beyond the one mentioned in the topic, but that's the main one I want to learn how to deal with.
<!--Saved by Quest 5.6.5832.26793-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Apocalypse">
<gameid>22a11c32-3773-4e03-9c85-88d59fec567e</gameid>
<version>1.0</version>
<firstpublished>2016</firstpublished>
<author>Patrik Siljestam</author>
<menufont>Georgia, serif</menufont>
<gridmap />
<showhealth />
<feature_limitinventory />
<feature_lightdark />
<enablehyperlinks type="boolean">false</enablehyperlinks>
<defaultbackground>White</defaultbackground>
<defaultforeground>Black</defaultforeground>
<povstatusattributes type="stringdictionary">
<item>
<key>Condition</key>
<value>Human</value>
</item>
<item>
<key>Ammo</key>
<value>!</value>
</item>
</povstatusattributes>
<pov type="object">Survivor</pov>
<start type="script">
</start>
<onhealthzero type="script">
SetObjectFlagOn (Survivor, "Zombie")
msg ("You have become a Zombie!")
player.Condition = "Zombie"
</onhealthzero>
</game>
<object name="Town Square">
<inherit name="editor_room" />
<attr name="grid_width" type="int">3</attr>
<attr name="grid_length" type="int">3</attr>
<object name="Survivor">
<inherit name="editor_object" />
<inherit name="editor_player" />
<inherit name="female" />
<drop type="boolean">false</drop>
</object>
<exit alias="east" to="Gas Station">
<inherit name="eastdirection" />
</exit>
<exit alias="southwest" to="Theatre">
<inherit name="southwestdirection" />
</exit>
<exit alias="north" to="Hospital">
<inherit name="northdirection" />
</exit>
</object>
<object name="Gas Station">
<inherit name="editor_room" />
<enter type="script">
Survivor.Ammo = Survivor.Ammo+6
</enter>
<exit alias="west" to="Town Square">
<inherit name="westdirection" />
</exit>
<object name="Flashlight">
<inherit name="editor_object" />
<take />
<feature_lightdark />
<attr name="feature_switchable" type="boolean">false</attr>
<lightstrength>strong</lightstrength>
<lightsource />
<displayverbs type="stringlist">
<value>Take</value>
</displayverbs>
<inventoryverbs type="stringlist">
<value>Drop</value>
</inventoryverbs>
</object>
</object>
<object name="Theatre">
<inherit name="editor_room" />
<dark />
<darkroomdescription>The Theatre is dark.</darkroomdescription>
<onexit type="script">
if (GetBoolean(Survivor, "Zombie")) {
}
else if (not GetBoolean(ZombieThea, "Dead")) {
msg ("Zombie attack!")
DecreaseHealth (50)
RemoveObject (ZombieThea)
SetObjectFlagOn (ZombieThea, "Dead")
}
</onexit>
<exit alias="northeast" to="Town Square">
<inherit name="northeastdirection" />
<lightsource />
<lightstrength>weak</lightstrength>
<runscript type="boolean">false</runscript>
</exit>
<object name="Revolver">
<inherit name="editor_object" />
<inherit name="container_limited" />
<visible />
<take />
<attr name="feature_usegive" type="boolean">false</attr>
<displayverbs type="stringlist">
<value>Take</value>
</displayverbs>
<inventoryverbs type="stringlist">
<value>Drop</value>
</inventoryverbs>
<attr name="feature_container" type="boolean">false</attr>
<open type="boolean">false</open>
<maxobjects type="int">12</maxobjects>
<close type="boolean">false</close>
</object>
<object name="ZombieThea">
<inherit name="editor_object" />
<alias>Zombie</alias>
<displayverbs type="stringlist">
<value>Fight</value>
<value>Shoot</value>
</displayverbs>
<take type="boolean">false</take>
<fight type="script">
DecreaseHealth (50)
RemoveObject (ZombieThea)
SetObjectFlagOn (ZombieThea, "Dead")
</fight>
<shoot type="scriptdictionary">
<item key="Pistol">
RemoveObject (ZombieThea)
SetObjectFlagOn (ZombieThea, "Dead")
</item>
</shoot>
</object>
</object>
<object name="Hospital">
<inherit name="editor_room" />
<dark />
<darkroomdescription>The Hospital is dark.</darkroomdescription>
<attr name="grid_width" type="int">2</attr>
<attr name="grid_length" type="int">2</attr>
<onexit type="script">
if (not GetBoolean(ZombieHosp, "Dead")) {
msg ("Zombie attack!")
DecreaseHealth (50)
RemoveObject (ZombieHosp)
SetObjectFlagOn (ZombieHosp, "Dead")
}
</onexit>
<exit alias="south" to="Town Square">
<inherit name="southdirection" />
<lightsource />
<lightstrength>weak</lightstrength>
</exit>
<exit alias="down" to="Hospital Basement">
<inherit name="downdirection" />
</exit>
<object name="ZombieHosp">
<inherit name="editor_object" />
<alias>Zombie</alias>
<displayverbs type="stringlist">
<value>Fight</value>
<value>Shoot</value>
</displayverbs>
<fight type="script">
DecreaseHealth (50)
RemoveObject (ZombieHosp)
SetObjectFlagOn (ZombieHosp, "Dead")
</fight>
<shoot type="scriptdictionary">
<item key="Pistol">
RemoveObject (ZombieHosp)
SetObjectFlagOn (ZombieHosp, "Dead")
</item>
</shoot>
</object>
</object>
<object name="Hospital Basement">
<inherit name="editor_room" />
<dark />
<onexit type="script">
if (not GetBoolean(ZombieHospBase, "Dead")) {
SetObjectFlagOn (ZombieHospBase, "Dead")
msg ("Zombie attack!")
DecreaseHealth (50)
RemoveObject (ZombieHospBase)
}
</onexit>
<object name="ZombieHospBase">
<inherit name="editor_object" />
<inherit name="male" />
<displayverbs type="stringlist">
<value>Fight</value>
<value>Shoot</value>
</displayverbs>
<attr name="feature_lightdark" type="boolean">false</attr>
<lightstrength>weak</lightstrength>
<attr name="feature_switchable" type="boolean">false</attr>
<alias>Zombie</alias>
<fight type="script">
DecreaseHealth (50)
RemoveObject (ZombieHospBase)
SetObjectFlagOn (ZombieHospBase, "Dead")
</fight>
<shoot type="scriptdictionary">
<item key="Pistol">
RemoveObject (ZombieHospBase)
SetObjectFlagOn (ZombieHospBase, "Dead")
</item>
</shoot>
</object>
<exit alias="up" to="Hospital">
<inherit name="updirection" />
</exit>
</object>
<verb>
<property>fight</property>
<pattern>fight</pattern>
<defaultexpression>"You can't fight " + object.article + "."</defaultexpression>
</verb>
<verb>
<property>shoot</property>
<pattern>shoot</pattern>
<defaultexpression>"You can't shoot " + object.article + "."</defaultexpression>
</verb>
<object name="ZombiePlay">
<inherit name="editor_object" />
<inherit name="editor_player" />
<inherit name="female" />
<alias>Zombie</alias>
<feature_player />
</object>
</asl>
HegemonKhan
20 Feb 2016, 07:17Ah, it's a very simple fix!
all you got to do is replace your use of 'player' with 'Survivor' (this is my fault that you tried the 'player.Condition="Zombie" statement), as you changed your default/main character Player Object from its default name of 'player', to 'Survivor', thus you no longer have a Player Object named 'player', and hence the: "unknown object or variable 'player' " error.
'game' Game Object -> 'Player' Tab -> 'script to run when health reaches zero' Scripting -> 'set variable ...' Script -> (see below)
change it from:
set variable player.Condition = [expression] "Zombie"
to:
set variable Survivor.Condition = [expression] "Zombie"
-----------
I can help you with some other stuff, but I need to know what your design plans are on it (your "zombie mode character" aspect: your 'ZombiePlay' Player Object)
you seem to be understanding most of this stuff well so far (well done!), from looking at your code
all you got to do is replace your use of 'player' with 'Survivor' (this is my fault that you tried the 'player.Condition="Zombie" statement), as you changed your default/main character Player Object from its default name of 'player', to 'Survivor', thus you no longer have a Player Object named 'player', and hence the: "unknown object or variable 'player' " error.
'game' Game Object -> 'Player' Tab -> 'script to run when health reaches zero' Scripting -> 'set variable ...' Script -> (see below)
change it from:
set variable player.Condition = [expression] "Zombie"
to:
set variable Survivor.Condition = [expression] "Zombie"
-----------
I can help you with some other stuff, but I need to know what your design plans are on it (your "zombie mode character" aspect: your 'ZombiePlay' Player Object)
you seem to be understanding most of this stuff well so far (well done!), from looking at your code

Siljestam
20 Feb 2016, 15:59I tried switching the to Survivor which did remove the error message, but still the Status bar to the right when I play test doesn't change...
It still says "Human".
Actually, I had to set the "Player Object Attribute Status" value for Condition to blank and script it as Human for the Survivor at the start of the game.
Thanks a bunch for the help! I'll tinker some more and return for the next problem I run into...
It still says "Human".
Actually, I had to set the "Player Object Attribute Status" value for Condition to blank and script it as Human for the Survivor at the start of the game.
Thanks a bunch for the help! I'll tinker some more and return for the next problem I run into...