Unknown object or variable

rarkon
14 Jan 2023, 15:26

Hello, I am trying to figure out the syntax for functions and if statements in Quest. Here is the code of a function called "Attack" that takes 2 parameters (attacker, target) and no return type. Here is the script of the function:
'''
msg ("Attack Function Started")
attacker.curr_aa_delay = attacker.max_aa_delay
EnableTimer (Combat)
SetTimerScript (Combat) {
msg ("looping")
if (attacker.curr_aa_delay = 0) {
msg ("attacker slashes for (10) damage")
attacker.curr_aa_delay = attacker.max_aa_delay
}
else {
attacker.curr_aa_delay = attacker.curr_delay - 1
}
}
'''
When I call this function I get an error: Error running script: Error compiling expression 'attacker.curr_aa_delay = 0': Unknown object or variable 'attacker'

The thing that doesn't make sense to me, is if Quest isn't able to find the attacker object, then why is it able to execute line 2 of the script "attacker.curr_aa_delay = attacker.max_aa_delay" perfectly?

Thanks.


DarkLizerd
14 Jan 2023, 18:14

Add the following line2 as the second line, right after your msg.
msg("attacker.curr_aa_delay = " & attacker.curr_aa_delay )
msg("attacker.max_aa_delay="& attacker.max_aa_delay)
(I think I get the msg part right.)
Basically, what I'm saying is print the 2 variables, maybe one isn't setup correctly and that is causing the problem.
When in doubt, add a bunch of msg statements to see what's happening.


mrangel
15 Jan 2023, 08:48

I assume that attacker is the name of a variable, rather than an object name?

That variable will only exist for the duration of the script that created it. It won't exist anymore when the timer comes to fire. You would need to do something like:

msg ("Attack Function Started")
attacker.curr_aa_delay = attacker.max_aa_delay
EnableTimer (Combat)
Combat.attacker = attacker
SetTimerScript (Combat) {
  msg ("looping")
  if (this.attacker.curr_aa_delay = 0) {
    msg ("attacker slashes for (10) damage")
    this.attacker.curr_aa_delay = this.attacker.max_aa_delay
  }
  else {
    this.attacker.curr_aa_delay = this.attacker.curr_aa_delay - 1
  }
}

(using an attribute of the timer to store which object is the attacker)


DarkLizerd
15 Jan 2023, 23:46

Looking at this again, it doesn't look like it will ever count down so that the attacker can attack, and I think THAT bug is here:
attacker.curr_aa_delay = attacker.curr_delay - 1
Shouldn't it be
attacker.curr_aa_delay = attacker.curr_aa_delay - 1

Also, have you set the values first? Quest may think that
attacker.curr_aa_delay=""
instead of
attacker.curr_aa_delay =0
A string + a number=error.


rarkon
19 Jan 2023, 02:34

Thank you mrangel. That was exactly the problem. I did not specify Combat.attacker = attacker. So inside the SetTimerScript loop it was not recognizing the attacker variable. Using your code it resolved the issue.