Home   Help Search Login Register  

Author Topic: Insanely full of error messages...  (Read 531 times)

0 Members and 1 Guest are viewing this topic.

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Insanely full of error messages...
« on: 19 Nov 2004, 03:04:45 »
ok, i'm making a script for a plane crash, that when it's killed will make it fall to the ground and slide across the ground for a few seconds, and randomly kill/injure people based on the speed of the plane and the height at which it gets killed.
here's my script (yes, its a long one. sorry)
Code: [Select]
_plane = _this select 0
_player = player
_rNum = 10
_killCount = 0
_CraterCounter = 50

#checkstatus
?!(alive _plane):_plane setdammage .7;_plane setfuel 0;goto "startcrash"
goto "checkstatus"

#startcrash
_plane lock true
_pilot = driver _plane
_cargo = crew _plane
?_player in _plane:_inplane = true;_player addeventhandler ["dammaged", {_player setdammage 0}];_player addeventhandler ["killed", {_player setdammage 0}];_player addeventhandler ["hit", {_player setdammage 0}]
_startheight = getpos _plane select 2
?(getpos _plane select 2) <= 2:goto "slide"
_pilot sidechat "Damn, we're hit! Brace for impact!"
#check
_plane setdammage .5
_plane setvelocity [(velocity _plane select 0), (velocity _plane select 1), (velocity _plane select 2) - .5]
?(getpos _plane select 2) <= 1:_plane setvelocity [(velocity _plane select 0), (velocity _plane select 1), (velocity _plane select 2) + 5];_InitVel = velocity _plane;titlecut ["","black out", 3];goto "slide"
goto "check"

#slide
_dir = getDir _plane
_vel1 = _InitVel select 0
_vel2 = _InitVel select 1
_vel1Diff = _vel1 * (5*10^(-20))
_vel2Diff = _vel2 * (5*10^(-20))
?(_dir > 90 && _dir <= 180):goto "southeast"
?(_dir > 180 && _dir <= 270):goto "southwest"
?(_dir > 270 && _dir <= 360):goto "northwest"

#northeast
_plane setpos [getpos _plane select 0,getpos _plane select 1,.75]
_plane setdammage .5
"_x setdammage 0" foreach _cargo
_plane setvelocity [(_vel1 - _vel1Diff),(_vel2 - _vel2Diff),(velocity _plane select 2)]
_vel1Diff = _vel1Diff * 2
_vel2Diff = _vel2Diff * 2
~.01
?_vel1Diff >= _vel1: _plane setvelocity [0,0,0];_finalHeight = (getpos _plane select 2);_plane setdammage 1;goto "randomsurvival"
_smokecounter = _smokeCounter - 1
?_CraterCounter == 0:bomb = "shell73" camcreate [getpos _plane select 0,getpos _plane select 1,(getpos _plane select 2)-2];_CraterCounter = 50
goto "northeast"

#southeast
_plane setpos [getpos _plane select 0,getpos _plane select 1,.75]
_plane setdammage .5
"_x setdammage 0" foreach _cargo
_plane setvelocity [(_vel1 - _vel1Diff),(_vel2 + _vel2Diff),(velocity _plane select 2)]
_vel1Diff = _vel1Diff * 2
_vel2Diff = _vel2Diff * 2
~.01
?_vel1Diff >= _vel1: _plane setvelocity [0,0,0];_finalHeight = (getpos _plane select 2);_plane setdammage 1;goto "randomsurvival"
_smokecounter = _smokeCounter - 1
?_CraterCounter == 0:bomb = "shell73" camcreate [getpos _plane select 0,getpos _plane select 1,(getpos _plane select 2)-2];_CraterCounter = 50
goto "southeast"

#southwest
_plane setpos [getpos _plane select 0,getpos _plane select 1,.75]
_plane setdammage .5
"_x setdammage 0" foreach _cargo
_plane setvelocity [(_vel1 + _vel1Diff),(_vel2 + _vel2Diff),(velocity _plane select 2)]
_vel1Diff = _vel1Diff * 2
_vel2Diff = _vel2Diff * 2
~.01
?_vel1Diff >= _vel1: _plane setvelocity [0,0,0];_finalHeight = (getpos _plane select 2);_plane setdammage 1;goto "randomsurvival"
_smokecounter = _smokeCounter - 1
?_CraterCounter == 0:bomb = "shell73" camcreate [getpos _plane select 0,getpos _plane select 1,(getpos _plane select 2)-2];_CraterCounter = 50
goto "southwest"

#northwest
_plane setpos [getpos _plane select 0,getpos _plane select 1,.75]
_plane setdammage .5
"_x setdammage 0" foreach _cargo
_plane setvelocity [(_vel1 + _vel1Diff),(_vel2 - _vel2Diff),(velocity _plane select 2)]
_vel1Diff = _vel1Diff * 2
_vel2Diff = _vel2Diff * 2
~.01
?_vel1Diff >= _vel1: _plane setvelocity [0,0,0];_finalHeight = (getpos _plane select 2);_plane setdammage 1;goto "randomsurvival"
_smokecounter = _smokeCounter - 1
?_CraterCounter == 0:bomb = "shell73" camcreate [getpos _plane select 0,getpos _plane select 1,(getpos _plane select 2)-2];_CraterCounter = 50
goto "northwest"

#randomsurvival
~3
_FallDistance = (_startHeight - _finalHeight)
_velocity = sqrt((_initvel select 0)^2 + (_initvel select 1)^2)
_Survival = (_FallDistance * _velocity)/2
?_Survival >= 100 && _Survival < 200:_rNum = 25;goto "kill"
?_Survival >= 200 && _Survival < 500:_rNum = 50;_killcount = 1;goto "kill"
?_Survival >= 500 && _Survival <= 1000:_rNum = 150;_killcount = 4;goto "kill"
?_Survival > 1000:_rNum = 250;_killcount = 15;goto "kill"

#kill
"_x setpos [((getpos _plane select 0) + (random 20) - (random 20)),((getpos _plane select 1) + (random 20) - (random 20)),(getpos _plane select 2)]" foreach _cargo
_nCargo = count _Cargo
_kill = random _killcount
_nCargo <= _kill:"_x setdammage 1" foreach _cargo;goto "finish"
"_x setdammage (random _rnum)" foreach _cargo

#KillLoop
?_kill == 0:goto "finish"
[b]_dead = _Cargo select ((random _nCargo)-1)[/b]
_dead setdammage 1
_cargo = _cargo - [_dead]
_nCargo = _nCargo - 1
_kill = _kill - 1
goto "killLoop"

#finish
removealleventhandlers _player
?_inplane:titlecut ["","black in",5]
exit

the current error message is this:
_dead = _Cargo select ((random _nCargo)-1)|#| error zero divisor
the line is in the label "killLoop" in my script, I have no clue what the error message means... ??? can someone help me? also if you happen to notice anything else wrong with it, please tell me.
Thanks  ;)
« Last Edit: 20 Nov 2004, 15:47:15 by Triggerhappy »

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Insanely full of error messages...
« Reply #1 on: 19 Nov 2004, 04:22:55 »
Haven't really looked at it yet, but it would help if you posted a simple test mission with everything set up, so we could see how far it gets before an error, etc.

But I noticed two errors already, without even looking close:

Code: [Select]
goto "southwest(Missing a quote)

Code: [Select]
goto ""northwest"(Double quotes)

Hey, are you using Chris's OFP Script Editor to write your scripts in? Because if not, you really, really should. It is in full color, so it is easy to see when you make stupid little typo mistakes like that. It has saved me SO much time since I started using it, because it makes those mistakes so much harder to miss.
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline ACF

  • Members
  • *
  • Llama?? Ain't that French for tanks?
Re:Insanely full of error messages...
« Reply #2 on: 19 Nov 2004, 10:31:34 »
_dead = _Cargo select ((random _nCargo)-1)|#| error zero divisor

The Select command needs an integer.  (random _nCargo)-1 is not only not an integer but could also go negative.  The error message itself is perhaps a bit misleading!

Use the Mod command to turn the random number into an integer.  Got to go - check the comref

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Insanely full of error messages...
« Reply #3 on: 19 Nov 2004, 21:44:19 »
~ACF
_nCargo = count _Cargo
but that makes _nCargo an integer, though. I've used that before and it worked

~General
about the goto thing, it doesn't have the double quotes and missing quotes, and doesn't show up that way on my screen like that either.
I also looked in my script to check it out and its right. no i don't use chris's editor. I've heard about it though and i'm not saying its bad, but i personally like not being given stuff that makes everything easier, because i don't think you really learn how to do anything that way.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Insanely full of error messages...
« Reply #4 on: 19 Nov 2004, 22:38:32 »
Presuming that nCargo was say.........12.......

(random _nCargo) could produce the number 6.76

then

((random _nCargo)-1) would be 5.76

And finally:

_Cargo select ((random _nCargo)-1) = _Cargo select 5.76

Which of course doesn't work


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

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Insanely full of error messages...
« Reply #5 on: 20 Nov 2004, 01:58:25 »
Quote
it doesn't have the double quotes and missing quotes, and doesn't show up that way on my screen like that either.
I was just directly copying and pasting off of what you put in your post. So unless you pasted your script wrong, then that stuff is there. Use the "find" feature to find exactly where the line is.

Quote
I personally like not being given stuff that makes everything easier, because i don't think you really learn how to do anything that way.
Well... I'm not sure how much you learn by accidentally pressing the wrong key, but not noticing it, and then spending hours trying to figure out why your script won't work because of it.

I like that program because I always make typos. His program usually makes those typos show up right away, so I can fix them right away, and get on with the actual scripting. I don't see what "learning" I am missing out on. It's not like the program writes the scripts for you or anything.  ::)

HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Insanely full of error messages...
« Reply #6 on: 20 Nov 2004, 07:25:12 »
Quote
Well... I'm not sure how much you learn by accidentally pressing the wrong key, but not noticing it, and then spending hours trying to figure out why your script won't work because of it
Quite...

The Chris' script editor won't automatically type you anything, it won't make you a script automatically if you type in "I want a script that xxxxx..."...
It just shows all functions, labels, comments etc in different colors...
It's much much much clearer that way... Absolutely great tool...

Even all pro (or proish) software, like for example Borland C++ builder etc use that same kind of colorization...
(Only people I know who won't use any enhanced editor are the html/etc enthusiasts who insist in proving something by typing ALL of their code in notepad ::) ;D )

Oh, and Planck is quite right...
When using random values to get and random index (to get stuff from an array in this case) you need to use the mod function... It makes the value as integer instead of floating point...

Also, when using count you must remember that an array of 12 elements returns 12 with count but the indexes start from 0 and end up in 11, so usually the zero divisor pops up when the script tries to use an element from the array that does not exist...
The 12th element in an array of 12 is array select 11, NOT array select 12...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Insanely full of error messages...
« Reply #7 on: 20 Nov 2004, 15:41:15 »
Quote
The 12th element in an array of 12 is array select 11, NOT array select 12...
covered that by subtracting one...oh crap i did it in the wrong place though

Offline Triggerhappy

  • Contributing Member
  • **
  • Llama, it's what's for dinner.
Re:Insanely full of error messages...
« Reply #8 on: 20 Nov 2004, 15:45:58 »
oh, i see where the double quotes are... yeah that was a copying problem