Command problem with #objects#
Talon
05 May 2018, 17:10Okay, the game of today is something like a godzilia game where you play the giant monster, (if people are old enough the concept is alot like the old Lionhead game black and white) )
The basic logic of the command , player uses stomp and gets a choice to be either playful or mean
Using Hell as a holding place for any victim destroyed throughout the game
The error that comes back is when you stomp meanly
Error running script: Error compiling expression 'object': Unknown object or variable 'object'
Command : Stomp #object#
if (HasAttribute(object, "stompable")) {
msg ("This is a placeholder for items")
}
else if (GetBoolean(object, "shrunk")) {
if (object.NPC = "victim") {
Ask ("Do you wish to stomp for play? ") {
if (result) {
msg ("The stompie takes no damage")
}
else {
MoveObject (object, Hell)
msg ("stompie is crushed flat")
}
}
}
}
Have a very similar sort of command that seems to work fine, even used it for a base for this but for some reason the "Mean" stomp throws up the flag
Im kinda perplexed that this code throws up an error seems simple, and obviously
mrangel
05 May 2018, 17:34object
only exists while the command script is being run.
The Ask
function basically tells Quest "Display a question to the player, and save this script to run next turn when they've answered".
As soon as the question is displayed on the screen, the command script is finished, and object
goes away.
Next turn, they click "Yes" or "No", and Quest tries to run the saved script. Which generates an error because it uses a variable that no longer exists.
You need to save the object somewhere. Maybe like this:
if (HasAttribute(object, "stompable")) {
msg ("This is a placeholder for items")
}
else if (GetBoolean(object, "shrunk")) {
if (object.NPC = "victim") {
this.current_victim = object
Ask ("Do you wish to stomp for play? ") {
if (result) {
msg ("The stompie takes no damage")
}
else {
MoveObject (stomp.current_victim, Hell)
msg ("stompie is crushed flat")
}
}
}
}
Talon
05 May 2018, 17:57Ahh, that explains alot of things, I've sorta come to use various items as holding places for various attributes on objects(alias and such) when coding more complex things, now I know why I had to rather than it just worked sometimes..
hegemonkhan
05 May 2018, 23:36quest has three types of VARIABLES (keeping this simple):
VARIABLES:
- 'Variable' VARIABLES
- 'Attribute' VARIABLES
- 'Argument/Parameter' VARIABLES: deals with Commands, Functions, and Script_Attributes+Delegates+Objects
a 'Variable' VARIABLE is "local" and "temporary", meaning that it is (1) destroyed upon its parent scripting finishing, and (2) only exists (usable) within its parent scripting (you can't use it any where else)
examples:
generic syntax example: NAME_OF_Variable = VALUE_OR_EXPRESSION
string_variable = "hk"
boolean_variable = true
// or: boolean_variable = false
integer_variable = 9
double_variable = 1.2345
object_variable = player
stringlist_variable = Split ("red;blue;yellow", ";")
script_variable => { msg ("hi") }
result = "yes"
handled = true
// or: handled = false
count = 0
notice how none of them have an attached Object
'Attribute' VARIABLES are global and "permanent" (so long as its containing/parent Object exists / still exists), meaning that they can be used anywhere
examples:
generic syntax example: NAME_OF_OBJECT.NAME_OF_ATTRIBUTE = VALUE_OR_EXPRESSION
player.alias = "HK"
player.strength = 100
// create ("orc")
orc.dead = false
game.state = 0
game.introduction = "welcome to my game, muwhahaha!"
// create ("katana")
katana.damage = 56.29145
player.weapon = katana
// create ("human_object")
human_object.human_race_stringlist_attribute = Split ("european;african;asian;arabian;american;australian", ";")
// create ("example_object")
example_object.example_string_attribute = "hi"
example_object.example_boolean_attribute = false
example_object.example_integer_attribute = 3
example_object.example_double_attribute = 6.666
example_object.example_object_attribute = player
example_object.example_stringlist_attribute = Split ("red;blue;yellow", ";")
example_object.example_script_attribute => { msg ("hi") }
notice how they all got an attached Object
too lazy/tired at the moment to give an example game of local ('Variable') VARIABLES vs global ('Attribute') VARIABLES
(sometime later... I'll write/post it up, but not now)