Home   Help Search Login Register  

Author Topic: wrong syntax  (Read 1492 times)

0 Members and 1 Guest are viewing this topic.

Offline 456820

  • Contributing Member
  • **
wrong syntax
« on: 26 Oct 2005, 10:31:36 »
okay i downloaded a script it was at a beta stage but it also worked
but i keep getting an error at the start of my mission from this part of the script

Code: [Select]
_list = _this
_count = count _list
_i=0
#loop

(_list select _i) addEventHandler ["fired",{_this exec "fired.sqs"}]

_i = _i + 1
?(_i < _count ):goto"loop"

that should add an event handler to every unit in game to load a script called fired.sqs which sets a different velocity to each round they fire making more realistic rifles
but i get some error about this line
Code: [Select]
(_list select _i) addEventHandler ["fired",{_this exec "fired.sqs"}]
i never had it in the demo mission so why should i have it now ? i copied all triggers and everything from the demo mission into my mission but i get an error

is there something wrong with the syntax and if so why did it not work with my mission but does in the demo mission

thanks

Offline Tyger

  • Former Staff
  • ****
  • I was at OFPEC when it still had dirt floors...
    • OFPEC
Re:wrong syntax
« Reply #1 on: 26 Oct 2005, 14:47:24 »
Quote
(_list select _i) addEventHandler ["fired",{_this exec "fired.sqs"}]

I believe that it should be
Quote
...{this exec "fired.sqs"}...
Not sure though.  :-\
"People sleep soundly at night only because rough men stand ready to do violence on their behalf." - George Orwell

MSG Mike Everret - We Will Never Forget - '75-'08

Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re:wrong syntax
« Reply #2 on: 26 Oct 2005, 14:56:03 »
I guess you're executing the script with the required values in a wrong format or just the wrong values.
But I would like to know your line that calls the script and the error message. - Try to shorten the line to getdir (_list select _i) or something so you can read more of the message.

Offline 456820

  • Contributing Member
  • **
Re:wrong syntax
« Reply #3 on: 26 Oct 2005, 15:00:05 »
i think i may of fixed it
it said error zero divisor i removed the space so it said this
Code: [Select]
(_list select _i) addEventHandler["fired",{_this exec "fired.sqs"}]
instead of
Code: [Select]
(_list select _i) addEventHandler ["fired",{_this exec "fired.sqs"}]
and its got rid of the error but im not sure if the scipts actually running

Offline Pilot

  • Contributing Member
  • **
Re:wrong syntax
« Reply #4 on: 26 Oct 2005, 17:17:23 »
How are you calling the script?

-Pilot

Offline 456820

  • Contributing Member
  • **
Re:wrong syntax
« Reply #5 on: 26 Oct 2005, 17:33:15 »
im calling it from a trigger in game which is anybody present once
condtion this
activation
thislist exec"init_event.sqs"

thats it it should add an event handler to every unit in the game

Offline Pilot

  • Contributing Member
  • **
Re:wrong syntax
« Reply #6 on: 26 Oct 2005, 17:37:04 »
You do have brackets around thislist, right?  eg,
[thislist] exec "init_event.sqs"

Also, in the script, try something like:
_list = _this select 0

That's the way I always do it and it always works for me, unless calling arrays uses a different format.

-Pilot

Offline 456820

  • Contributing Member
  • **
Re:wrong syntax
« Reply #7 on: 26 Oct 2005, 17:42:08 »
nope no brackets thats how it came in the demo mission and it worked fine there
its exactly how its shown
ill have ago your way

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re:wrong syntax
« Reply #8 on: 26 Oct 2005, 19:08:39 »
You do have brackets around thislist, right?  eg,
[thislist] exec "init_event.sqs"

Also, in the script, try something like:
_list = _this select 0

That's the way I always do it and it always works for me, unless calling arrays uses a different format.

-Pilot

No need for an array if you only have one argument. That's what the brackets do, they give you an array. Array of one variable is kind of pointless...? Of course an array variable can also be "one argument".

:P

If you use brackets for one argument, OFP has to create an array to hold the one argument, then OFP passes the array to the script and then you need to force OFP to pick the only item from the newly-created array by using select. Sounds like an overkill for just one argument.

Just a hint to reduce typing when you write your scripts... and OFP likes it too when your script statements are shorter.

:)
« Last Edit: 26 Oct 2005, 21:02:02 by Baddo »

Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re:wrong syntax
« Reply #9 on: 26 Oct 2005, 20:00:07 »
i think i may of fixed it
it said error zero divisor i removed the space so it said this
Code: [Select]
(_list select _i) addEventHandler["fired",{_this exec "fired.sqs"}]
instead of
Code: [Select]
(_list select _i) addEventHandler ["fired",{_this exec "fired.sqs"}]
and its got rid of the error but im not sure if the scipts actually running

You could try (_list select _i) fire (primary weapon (_list select _i)) or something similar to find out.

I've got the feeling the removed space only creates an unknown/not wrong situation for the debug messages.
Does the # mark the error at _list? Your script call looks good, but this error is likely for situations were the script doesn't find the array the user expected. To have a look at the actual array, execute the test line hint format ["%1",_list] in your script. - It should display the array content in a hint. If your OFP crashes to desktop, make the size of the trigger smaller for this test.
Maybe the real problem is located in filling the thislist array with unit names, because of not working trigger settings.
« Last Edit: 26 Oct 2005, 20:01:21 by Trapper »

Offline Pilot

  • Contributing Member
  • **
Re:wrong syntax
« Reply #10 on: 27 Oct 2005, 02:36:39 »
@Baddo
That's interesting, I never would have though of that.  Very interesting...

Thanks for the clarification :-*

-Pilot

Offline benreeper

  • Members
  • *
  • I'm a llama!
Re:wrong syntax
« Reply #11 on: 27 Oct 2005, 04:54:30 »
Does your trigger cover the entire map?
--Ben

Offline 456820

  • Contributing Member
  • **
Re:wrong syntax
« Reply #12 on: 27 Oct 2005, 09:22:57 »
yep
x and y axis are both 99999
thats hwat i do with all my triggers which need to cover the whole map and they seem to work

a way of getting this to work easier is there away of just one line to add an event handler to every unit with in
allunit
as in
allunit = thislist
in the activation of a trigger i could put that in the init.sqs to run the event handlers it would save all this on the script
cheers