Problems with setting boolean attribute true
chellkafka
25 Apr 2014, 17:47So, I created an attribute for an object (hook up, in the game file) called "wired" which should be set true if the player uses the wire on the object. now, I created a pull verb for a lever that runs an if script that checks if the attribute is true. but somehow it ain't working. could somebody look at the file? or does anybody have an idea?
HegemonKhan
25 Apr 2014, 19:32without looking at your file, here's how booleans~flags work:
to initially set (and ALSO to re-set, aka change), a boolean:
in code:
as a tag:
<attr name="blah" type="boolean">false</attr>
~OR~
<attr name="blah" type="boolean">true</attr>
as a script:
Object.Attribute = Value_or_Expression
Object.Attribute = false
~OR~
Object.Attribute = true
do note the: *NO* quotes on the Value, this is because 'false' and 'true' are special, they're recognized as Booleans'~Flags' Values
in gui-editor:
(whatever) Object -> Attributes (tab) -> Attributes -> Add ->
Attribute Name: ________
Attribute Type: boolean
Attribute Value: (true or false)
and there's also the scripts:
SetObjectFlagOn: false -> true
SetObjectFlagOff: true -> false
and the "if" Script too:
if -> [EXPRESSION] -> Object.Attribute = false_or_true ->
-> then do: (whatever) Script (add a script)
else if > [EXPRESSION] -> Object.Attribute = true_or_false ->
-> then do: (whatever) Script (add a script)
----------
to then use a boolean's setting, you use the "if" Script (in code below), an example:
to initially set (and ALSO to re-set, aka change), a boolean:
in code:
as a tag:
<attr name="blah" type="boolean">false</attr>
~OR~
<attr name="blah" type="boolean">true</attr>
as a script:
Object.Attribute = Value_or_Expression
Object.Attribute = false
~OR~
Object.Attribute = true
do note the: *NO* quotes on the Value, this is because 'false' and 'true' are special, they're recognized as Booleans'~Flags' Values
in gui-editor:
(whatever) Object -> Attributes (tab) -> Attributes -> Add ->
Attribute Name: ________
Attribute Type: boolean
Attribute Value: (true or false)
and there's also the scripts:
SetObjectFlagOn: false -> true
SetObjectFlagOff: true -> false
and the "if" Script too:
if -> [EXPRESSION] -> Object.Attribute = false_or_true ->
-> then do: (whatever) Script (add a script)
else if > [EXPRESSION] -> Object.Attribute = true_or_false ->
-> then do: (whatever) Script (add a script)
----------
to then use a boolean's setting, you use the "if" Script (in code below), an example:
<object name="orc">
<inherit name="editor_object" />
<attr name="dead" type="boolean">false</attr>
<attr name="displayverbs" type="listextend">Fight</attr>
<attr name="fight" type="script">
if (orc.dead = true) {
msg ("The orc is already dead, silly. But, it then magically comes back to life again.")
orc.dead = false
} else if (orc.dead = false) {
msg ("You kill the orc.")
orc.dead = true
}
</attr>
</object>
chellkafka
25 Apr 2014, 20:55ok, found the problem now. just wrote "wired" in attribute instead of "hookup.wired".
the thing is, i started out with "hookup.wired" but the game didn't recognise it. don't know what changed, but yeah, it works now.
the thing is, i started out with "hookup.wired" but the game didn't recognise it. don't know what changed, but yeah, it works now.
HegemonKhan
26 Apr 2014, 04:11if you just have 'wired' (the Attribute), for quest's terminology, we call it a 'Variable', as it's local, it's stuck to only that script which it is in, so it can't be used outside in some other script.
when you 'attach' an Attribute to an Object (in code: Object.Attribute), then it can be used anywhere, so long as the Object still exists in your game (not removed, nor destroyed).
for example (pseodo code just for conception):
Use of a built-in Variable (result):
Script1:
get input {
-> // quest internally sets the Variable: result = your_typed_in_input
-> if (result = "yes") {
->-> // Do (whatever) script
-> } else if (result = "no") {
->-> // Do (whatever) script
-> }
}
// *NO* error, it works fine.
Script2:
-> if (result = "yes") {
->-> // Do (whatever) script
-> } else if (result = "no") {
->-> // Do (whatever) script
-> }
}
// ERROR !!!! result is not defined~set... result = ??? ... can't compute... ERROR !!!!
Use of a built-in Attribute (alias ~ player.alias):
<object name="player">
-> <inherit name="editor_object" />
-> <alias>unknown</alias>
</object>
Script0:
get input {
msg ("What is your name?")
get input {
-> player.alias = result
-> msg (player.alias)
}
Script1:
if (player.alias = "HK") {
-> player.alias = "Kafka"
-> msg (player.alias)
} else if (player.alias = "Kafka") {
-> player.alias = "HK"
-> msg (player.alias)
}
// *NO* error, it works fine.
Script2:
if (player.alias = "orc") {
-> // Do (whatever) script
} else if (player.alias = "ogre") {
-> // Do (whatever) script
}
// *NO* error, it works fine.
when you 'attach' an Attribute to an Object (in code: Object.Attribute), then it can be used anywhere, so long as the Object still exists in your game (not removed, nor destroyed).
for example (pseodo code just for conception):
Use of a built-in Variable (result):
Script1:
get input {
-> // quest internally sets the Variable: result = your_typed_in_input
-> if (result = "yes") {
->-> // Do (whatever) script
-> } else if (result = "no") {
->-> // Do (whatever) script
-> }
}
// *NO* error, it works fine.
Script2:
-> if (result = "yes") {
->-> // Do (whatever) script
-> } else if (result = "no") {
->-> // Do (whatever) script
-> }
}
// ERROR !!!! result is not defined~set... result = ??? ... can't compute... ERROR !!!!
Use of a built-in Attribute (alias ~ player.alias):
<object name="player">
-> <inherit name="editor_object" />
-> <alias>unknown</alias>
</object>
Script0:
get input {
msg ("What is your name?")
get input {
-> player.alias = result
-> msg (player.alias)
}
Script1:
if (player.alias = "HK") {
-> player.alias = "Kafka"
-> msg (player.alias)
} else if (player.alias = "Kafka") {
-> player.alias = "HK"
-> msg (player.alias)
}
// *NO* error, it works fine.
Script2:
if (player.alias = "orc") {
-> // Do (whatever) script
} else if (player.alias = "ogre") {
-> // Do (whatever) script
}
// *NO* error, it works fine.