OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: tehhunter on 03 Jul 2005, 00:17:05
-
I'm currently trying to make a small script for some camCreated artillery. I am an experienced programer, yet I can't figure out exactly why I keep getting the error "Scalar Bool Array String 0xfcffffcef".
Also, I made a small script (included) that picks a random vehicle ammo to use for the explosion, so more variety is included. However, it will only return "Shell73" or the aforementioned error as the variable _uwp (which is the weapon to be used).
_vwp# variables are the vehicle ammos to choose from.
So, if anyone has any ideas, I would be most delighted to hear them. Thanks.
_center = getPos gl1
;* Insert your diameter here:
_di = 150;
;* Insert the total amount of rounds to shoot here:
_total = 20
;* Edit these if you know what you are doing:
_count = 0
_vwp0 = "Shell125"
_vwp1 = "Heat125"
_vwp2 = "Heat73"
_vwp3 = "Shell73"
#leapback
_ri = random 4
?(_ri < 0):_uwp = _vwp0
?(_ri < 1):_uwp = _vwp1
?(_ri < 2):_uwp = _vwp2
?(_ri < 3):_uwp = _vwp3
mk sideChat Format["%1 chosen by %2",_uwp,_ri]
hint format ["%1", _uwp]
_rx = random _di
_ry = random _di
_cx = _rx + _center select 0
_cy = _ry + _center select 1
_cz = 300
_pos set [0,_cx]
_pos set [1,_cy]
_pos set [2,_cz]
mk sideChat Format["%1 AND %2",_pos,_uwp]
_uwp camCreate _pos
_count = _count + 1
~3
?(_count < _total):goto leapback
?!(_count < _total):exit
-
Several problems lie here:
?(_ri < 0):_uwp = _vwp0
?(_ri < 1):_uwp = _vwp1
?(_ri < 2):_uwp = _vwp2
?(_ri < 3):_uwp = _vwp3
Think about it. What is _uwp if _ri is say 0.5?
Answer: _vwp3. Well first it is set to _vwp1 because it is less than 1; then it is set to _vwp2 because it is less than 2 .... but it will end up at _vwp3
And how on earth can _ri be less than 0?
and what happens if _ri >= 3 but < 4? _uwp is undefined and that gives you your scalar thing.
Try:
_shells = ["Shell125","Heat125","Heat73","Shell73"]
_thisone = random (count _shells)
_thisone = _thisone - (_thisone % 1)
_shell = _shells select _thisone
-
I think the problem might be here.
_ri = random 4
?(_ri < 0):_uwp = _vwp0
?(_ri < 1):_uwp = _vwp1
?(_ri < 2):_uwp = _vwp2
?(_ri < 3):_uwp = _vwp3
If we presume that random 4 comes up with something like 0.55.......then all 3 of the last checks will be true, but the last one will be the effective one:
Shell73
On another note......I think random 4 will generate a number between 0 and 4, I can't see it ever generating a number less than 0, so the first check is a little redundant.
Try something like this:
_ri = random 4
?(_ri >= 0) && (_ri < 1) :_uwp = _vwp0
?(_ri >= 1) && (_ri < 2) :_uwp = _vwp1
?(_ri >= 2) && (_ri < 3) :_uwp = _vwp2
?(_ri >= 3) && (_ri <= 4) :_uwp = _vwp3
Something like that anyway........it's late ::)
Planck
-
alternatively, utilise the mod command (http://www.ofpec.com/editors/comref.php?letter=M#mod) to round your random numbers...
see? 'mods' are very handy to have around ;)
-
You guys are getting slow in your old age ;D
-
11 seconds wasn't too bad.
Planck
-
There are the quick and there are the dead ;D
-
I think the problem might be here.
_ri = random 4
?(_ri < 0):_uwp = _vwp0
?(_ri < 1):_uwp = _vwp1
?(_ri < 2):_uwp = _vwp2
?(_ri < 3):_uwp = _vwp3
If we presume that random 4 comes up with something like 0.55.......then all 3 of the last checks will be true, but the last one will be the effective one:
Shell73
On another note......I think random 4 will generate a number between 0 and 4, I can't see it ever generating a number less than 0, so the first check is a little redundant.
Try something like this:
_ri = random 4
?(_ri >= 0) && (_ri < 1) :_uwp = _vwp0
?(_ri >= 1) && (_ri < 2) :_uwp = _vwp1
?(_ri >= 2) && (_ri < 3) :_uwp = _vwp2
?(_ri >= 3) && (_ri <= 4) :_uwp = _vwp3
Something like that anyway........it's late ::)
Planck
Thanks, that worked well. I forgot to check which way the signs were pointing. Always something small like that when I can't fix something.
Anyways, I only have one more error and that is the _pos variable.
Its supposed to be the position of the gamelogic +/- a random number between 140 and 0 for both X and Y, to create a circular bombardment effect. However, I can't set the arrays properly.
From what I understand, you set arrays by
_array = [0,0,0]
_array set [0,_X]
_array set [1,_Y]
_array set [2,_Z]
However, this returns the 'scalar bool' error when I try to use it along with camcreate in the above script. Is there some other way to set an array with 3 variables?
-
Try defining _pos as an array at the beginning of the script.
_pos = []
I think that s right, as I said before .....it's late, I really should go to bed.
Planck
-
Well Planck it looks like being first and being right is not enough, and even when I give the guy some code that will work with any number of shells without creating a whole new set of variables he just ignores it! >:(