Home   Help Search Login Register  

Author Topic: Basic "Fired" EH problem w/ variables  (Read 1630 times)

0 Members and 1 Guest are viewing this topic.

Lean Bear

  • Guest
Basic "Fired" EH problem w/ variables
« on: 24 Jul 2005, 13:11:17 »
OK, I've got a pretty complex script I'm working on, but its the simple easy things I keep slipping up on :P

I've got an Event Handler in my script as follows:

_unit addEventHandler ["fired", {unitFired = true}]

but incredably OFP doesn't like it. It alwasy comes up with some sort of error that cahnges to another error no matter how I cahnge the syntax. All I want to do is when the unit fires, the global varibable unitFired switches to "true".

I've tried almost every possiblity, but I'm beginning to think that EHs can't handle variables (at least, not global variables).

I really don't want to make a loop like:

_unit addEventHandler ["fired", {goto "Loop"}]

#Loop

unitFired = true


because the script looks messy enough. But it looks like that's the way its going...

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Basic "Fired" EH problem w/ variables
« Reply #1 on: 24 Jul 2005, 13:17:27 »
Have you tried declaring unitfired = false in your init.sqs to initialise the variable first?


Planck
I know a little about a lot, and a lot about a little.

Lean Bear

  • Guest
Re:Basic "Fired" EH problem w/ variables
« Reply #2 on: 24 Jul 2005, 13:19:21 »
Of course ;)

Does OFP read the init.sqs when you do a mission preview in the Miss Ed?

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Basic "Fired" EH problem w/ variables
« Reply #3 on: 24 Jul 2005, 13:21:53 »
just tried it myself, works fine.

i set up the fired eventhandler to make 'varfired' true, and set up a trigger to give me a hint when 'varfired' was true. hit preview, fire, and ping, the hint appears.

sorry to give just this "mine works and yours doesn't", but perhaps the problem lies elsewhere?

edit - all this without defining 'varfired' first too....
« Last Edit: 24 Jul 2005, 13:22:34 by bedges »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Basic "Fired" EH problem w/ variables
« Reply #4 on: 24 Jul 2005, 13:23:51 »
In my experience......yes......it does read it in the mission preview.


Planck
I know a little about a lot, and a lot about a little.

Lean Bear

  • Guest
Re:Basic "Fired" EH problem w/ variables
« Reply #5 on: 24 Jul 2005, 13:28:31 »
Hmm, I can't think of any reason why it wouldn't work.

Its right at the start of the script as well. As I say, OFP always found a problem with the syntax and then just didn't want ot continue wih the script (well - that EH was pretty vital to the rest of the script running porperly anyway).

The next line reads:

@unitFired
goto "Loop"


So I can't see anything wrong with that - or at least nothing that wouldn't make the EH work properly.

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Basic "Fired" EH problem w/ variables
« Reply #6 on: 24 Jul 2005, 13:37:14 »
unitFired isn't a reserved variable is it?

if you can get a copy of the error generated, that may help...

Lean Bear

  • Guest
Re:Basic "Fired" EH problem w/ variables
« Reply #7 on: 25 Jul 2005, 12:25:39 »
Whu-oh, looks like my last post didn't make it through the wires.

Basically, I was going to say that there wasn'tmuch point as whatever I change the syntax too, there's always an error.

The most common ones are:

"Error: 'addEventHandler' expected Object; found Array"
"Error: '=' unknown operator"
"Error: '' " //don't get this one :-\

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Basic "Fired" EH problem w/ variables
« Reply #8 on: 25 Jul 2005, 17:36:19 »
well, as far as my eyes can see, the syntax is fine, like i say it works for me no problem. the only other element that could be the cause is _unit.

how is _unit defined? are you pulling it from the [variable] exec "script.sqs" call, or is it defined elsewhere?
« Last Edit: 25 Jul 2005, 17:36:32 by bedges »

Lean Bear

  • Guest
Re:Basic "Fired" EH problem w/ variables
« Reply #9 on: 25 Jul 2005, 20:06:00 »
Yeah, you got it.

[_unit] exec "script.sqs"

Then, in "Script.sqs"

_unit = _this select 0

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:Basic "Fired" EH problem w/ variables
« Reply #10 on: 25 Jul 2005, 21:19:32 »
mkay, i'm embarrassed to ask this, but you are using the name of a unit as [name_of_unit] exec "script.sqs" right? not [_unit]....  :-[

of course you are, that's a silly thing to ask, but without seeing your whole situation, i'm clutching at straws here...
« Last Edit: 25 Jul 2005, 21:20:04 by bedges »

Lean Bear

  • Guest
Re:Basic "Fired" EH problem w/ variables
« Reply #11 on: 26 Jul 2005, 11:35:49 »
Again, you're spot on bedges.

For example:

"west1" exec "Script.sqs"

Offline Killswitch

  • Members
  • *
  • Peace, cheese and ArmA
Re:Basic "Fired" EH problem w/ variables
« Reply #12 on: 26 Jul 2005, 11:59:48 »
Again, you're spot on bedges.

For example:

"west1" exec "Script.sqs"
If that is how you want to use Script.sqs, the line that reads
Code: [Select]
_unit = _this select 0will of course not work. The select command operates on arrays, not strings. You are passing a string as parameter to the script, not an array.

However
Code: [Select]
_unit = call (_this select 0)will work.

If you really do want do use "_unit=_this select 0", you'd have to execute Script.sqs using
Code: [Select]
[west1] exec "Script.sqs"

Lean Bear

  • Guest
Re:Basic "Fired" EH problem w/ variables
« Reply #13 on: 26 Jul 2005, 12:05:41 »
Sorry, I wasn't being clear about that last post.

I just put that as an example to show bedges that I'm not using:

_unit exec "Script.sqs"

to call the script.

I'm using an array anyway, something like:

[_unit, _vehicle, _a]

So when I call the script, it would be like:

[west1, bmp1, 20] exec "Script.sqs"

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:Basic "Fired" EH problem w/ variables
« Reply #14 on: 26 Jul 2005, 16:11:52 »
You should check all your variables, if there isn't some
dbl-use of variables somewhere in your mission.

Exec syntax looks fine but the error message leads to
that west1 is not what it is intended to be.

Is west1 maybe used as something else too?

:edit - try to debug by using hint format to display the
context of the your variables too  
Sooner or later you'll find the bugger then ;)

~S~ CD
« Last Edit: 26 Jul 2005, 16:13:25 by Chris Death »
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted