Home   Help Search Login Register  

Author Topic: random or and/or problem  (Read 1353 times)

0 Members and 1 Guest are viewing this topic.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
random or and/or problem
« on: 06 Jun 2006, 07:57:48 »
I'm working on a UAV (air recon) training mission.

In the begining, a random script setPos one, two or three armored target(s) to a getMarkerPos. The player must recon this area and if he/she sees one armored target call the alpha radio code, if he/she sees two, then Bravo and three - Charlie... That's simple.

The random script is here:

Code: [Select]
_rnd = random 99

at1 setPos getMarkerPos "dot1"
targetcnt = 1
? (_rnd < 33) : goto "vege"
at2 setPos getMarkerPos "dot2"
targetcnt = 2
? (_rnd < 66) : goto "vege"
at3 setPos getMarkerPos "dot3"
targetcnt = 3

#vege

exit

if random 99 is smaller than 33 then only one armored target positioning to the area.
if random 99 is bigger than 33 but smaller then 66, two armored target and so on...

Finally I put three Triggers with radio codes: alpha, bravo, charlie.

if player use the alpha (0-0-1) I change the 'alphacall' variable to true.
if player use the bravo (0-0-2) I change the 'bravocall' variable to true. etc.
Of course I initialize 'alphacall' and other variables to false in init.sqs.

Then I insert two triggers: one for success and one for fail.
The success trigger condition is:
Code: [Select]
((alphacall and targetcnt == 1) or (bravocall and targetcnt == 2) or (charliecall and targetcnt == 3))The activation is a mission End.

The fail trigger condition is:
Code: [Select]
((alphacall and targetcnt != 1) or (bravocall and targetcnt != 2) or (deltacall and targetcnt != 3))Tha activation is a Cheater warning and mission Loose.
(if the player don't want use the air recon device and guess, (and he have badluck) the mission is failed)

The PROBLEM is: this mission sometimes works, but other times doesn't.
Doesn't work means: there are three armored target and I call the Charlie code, but mission failed.

I tried to solve this problem in whole weekend, but I don't know what is the problem.

I attached the reduced version of this problem on desert island.

[attachment deleted by admin]
Fix bayonet!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: random or and/or problem
« Reply #1 on: 06 Jun 2006, 10:00:40 »
brackets.

Code: [Select]
((alphacall and (targetcnt == 1)) or (bravocall and (targetcnt == 2)) or (charliecall and (targetcnt == 3)))
Code: [Select]
((alphacall and (targetcnt != 1)) or (bravocall and (targetcnt != 2)) or (deltacall and (targetcnt != 3)))
tested and works every time.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: random or and/or problem
« Reply #2 on: 06 Jun 2006, 11:12:24 »
Thanks bedges!

Double thanks for open the sound topic too.

Brackets... Damn. In the first time I used nor a number variable (targetcnt) but a boolean variable: (alphacall and alpha) and didn't work and then I changed to number variable and I didn't think to this is the problem. Thanks again...

Fix bayonet!

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: random or and/or problem
« Reply #3 on: 07 Jun 2006, 08:30:39 »
Sorry bedges, but doesn't work...  :(

I try your version 10 times and 3 times it works wrong. Any suggestion???

 ???

I inserted a debug hint in my script like this:

Code: [Select]
_rnd = random 99

at1 setPos getMarkerPos "dot1"
targetcnt = 1
Hint "1"

? (_rnd < 33) : goto "vege"
at2 setPos getMarkerPos "dot2"
targetcnt = 2
Hint "2"

? (_rnd < 66) : goto "vege"
at3 setPos getMarkerPos "dot3"
targetcnt = 3
Hint "3"

#vege

exit


And very strange happened: sometimes I saw 2 targets but the hint say only "1". And other times I saw 3 targets but Hint say "2".
How can it possible?

I think the bug is in the script, not in the triggers.
Fix bayonet!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: random or and/or problem
« Reply #4 on: 07 Jun 2006, 09:48:24 »
only thing i can think of is the random number ranges. try this:

Code: [Select]
at1 setPos getMarkerPos "dot1"
targetcnt = 1

_rnd = random 99

? (_rnd > 33) and (_rnd <= 65): at2 setPos getMarkerPos "dot2"; targetcnt = 2

? (_rnd > 65) and (_rnd <= 99): at3 setPos getMarkerPos "dot3"; targetcnt = 3

hint format ["There are %1 targets", targetcnt]

exit

EDIT - true enough, random returns an integer so 65.5 wouldn't have been caught. well spotted ;)

script amended.
« Last Edit: 07 Jun 2006, 09:59:08 by bedges »

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: random or and/or problem
« Reply #5 on: 07 Jun 2006, 09:53:08 »
Thanks, but I think about it (Now I'm in office and I can't try, only at home):

I read the random function return with a real number and not with an integer.
And if the value of _rnd is 65.5 ... OK. It's not problem, than happen the same if the _rnd is smaller than 33.
Thanks. I'll try it.
Fix bayonet!

Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re: random or and/or problem
« Reply #6 on: 07 Jun 2006, 14:33:12 »
Solution is really simple and I was searching for an hour.  :'(
I know a guy that works to hard on his campaign... 8)
Never again execute the init.sqs in init lines or anywhere else in your missions. :D

After adding ~1 to every part of your script and using only one hint format at the end of the script, I was able to notice that sometimes two hints showed up with different random values.
Init.sqs (which executes randomtarget.sqs) was executed two times! Then a search in mission.sqm showed me that you executed init.sqs in the init line of the player.
Well, init.sqs is the first thing that always executes automaticly in a mission. You don't have to execute it manualy.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: random or and/or problem
« Reply #7 on: 07 Jun 2006, 14:40:22 »
Thanks Trapper!!!!

I never know that... I saw in a lots of mission that player init line there is an exec "init.sqs".
Thanks a lot!!!!
Fix bayonet!

Offline Trapper

  • Honoured Contributor
  • ***
  • I'm a llama!
Re: random or and/or problem
« Reply #8 on: 07 Jun 2006, 14:47:57 »
Lol, I was almost believing your example was infected by an OFP virus which turns scripting logic up side down.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
Re: random or and/or problem
« Reply #9 on: 07 Jun 2006, 15:05:05 »
 ;D ;D ;D ;D

Yeah, a new challenge: OFP virus...  ;D
Fix bayonet!