Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
nschlein

Registered:
Posts: 174
Reply with quote  #1 
Oh great Hive Mind, lend me your assistance!

I've got a script in which I'm using a pair of randomly generated variables, and they clearly aren't using their full range potential.

  • The variables generate an X and Z value between 1 and 99999, copies this to two variables named SectorX & Z, and starts a timer.
  • SectorX/Z is checked against a series of 25 intermediary events to create a pop-up warning about the location.
  • When the timer expires, a random object (based on another variable set elsewhere) is spawned at the designated coordinates.


It works...except that I never get values outside of sectors A4, A5, B4, and B5.  That indicates the system isn't giving me anything above 40,000 on either the X or Z variable.


(In a prior configuration, it worked fine (or at least better) as just two parts: the first part generated location variables named TempX and TempZ, created the random object, and copied TempX and TempZ/20000 to another variable.  The second part checked that variable to generate the warning message.)


Can anyone tell me what is happening?  I could take out the SectorX and SectorZ variables--those are now unnecessary and left over from my original version--but the problem is with the initial variable generation..

Here is a sample of the code (I've removed 24 of the sector warnings):

<event name="Set Sector Location" id_arme="955a49aa-6c9d-409e-84c9-cfd393bf2bd5">
  <if_variable name="Sector" comparator="EQUALS" value="1.0" />
  <set_timer name="RandomEffect" seconds="10" />
  <set_variable name="RandomX" randomIntLow="1" randomIntHigh="99998" integer="yes" />
  <set_variable name="RandomZ" randomIntLow="1" randomIntHigh="99998" integer="yes" />
  <set_variable name="SectorX" value="RandomX/20000" />
  <set_variable name="SectorZ" value="RandomZ/20000" />
  <set_variable name="Sector" value="2.0" integer="yes" />
</event>



<event name="Sector A5 Warning" id_arme="96944db7-6c9b-4577-ab5f-c8a6d715c535" parent_id_arme="eef93087-af9d-410e-8877-f21a8ccaf6d6">
<if_variable name="SectorX" comparator="LESS" value="1.0" />
<if_variable name="SectorX" comparator="GREATER" value="0.0" />
<if_variable name="SectorZ" comparator="GREATER" value="0.0" />
<if_variable name="SectorZ" comparator="LESS" value="1.0" />
<if_variable name="Sector" comparator="EQUALS" value="2.0" />
<warning_popup_message message="Spatial Disruption Detected: A5" consoles="MS" name="" />
<incoming_comms_text from="Command" type="SIDE STATUS STATION">A new disruption has been detected in sector A5.^^Caution is advised.</incoming_comms_text><set_variable name="SectorX" value="-1.0" />
<set_variable name="SectorZ" value="-1.0" /><set_variable name="Sector" value="3.0" integer="yes" /></event>


<event name="Monster" id_arme="c68506ac-9493-47b5-8f09-bfd15afc7887" parent_id_arme="eef93087-af9d-410e-8877-f21a8ccaf6d6">
<if_timer_finished name="RandomEffect" comparator="EQUALS" value="2.0" />
<if_variable name="Sector" comparator="EQUALS" value="3.0" />
<if_variable name="Feature" comparator="GREATER" value="0.0" />
<if_variable name="Feature" comparator="LESS_EQUAL" value="20.0" />
<create type="monster" x="RandomX" y="0.0" z="RandomZ" monsterType="3" />
<set_variable name="RandomX" value="0.0" integer="yes" />
<set_variable name="RandomZ" value="0.0" integer="yes" />
<set_variable name="Feature" value="0.0" integer="yes" />
<set_variable name="Sector" value="0.0" integer="yes" /></event>




EDIT:
Also, I just realized that when it is spawning enemies (elsewhere in the code) I have a variable named TempZ which is supposed to vary between 1000 and 90,000.  This also seems to stop somewhere between 20,000 and 40,000. 
Is that just a limit in Artemis?

FURTHER UPDATE:
I have still not found a direct resolution of this issue.  I fixed the first problem by spawning one variable (1-25) to identify the sector and then a second pair in increments of 20000 based on it.  The second I am multiplying two variables together.  Works, but not satisfying.
Darrin

Registered:
Posts: 434
Reply with quote  #2 
My best guess is whatever Artemis is using to generate random numbers is using short integers, so the range of the random output is capped at 32,767. If the RNG gets some value over 32,767, it may be "wrapping" around to some {value} - 32,767. 

You can assign values to integers above 32,767 without wrapping, so this looks like a quirk of the RNG.

To get around this, you can use a random float, or multiply the integer by 3, or use a smaller range such as 1 through 20,000 with a x5 multiplier. 


__________________
Call Sign (EF/TSN): Bassellope

nschlein

Registered:
Posts: 174
Reply with quote  #3 
That's basically what I did, but I'm curious--how did you come up with 32,767?

Edit: Okay, I looked it up and sort of understand--at least enough for my purposes.

Thanks!
Darrin

Registered:
Posts: 434
Reply with quote  #4 
Quote:
Originally Posted by nschlein
That's basically what I did, but I'm curious--how did you come up with 32,767?


I fired up a test mission, defined a half-dozen-or-so variables with random integers, and then looked at what values were being assigned via F7 debug. Very few values over 30K, nothing over 40K. I knew integers had a max value, couldn't remember if it was 32xxx or 64xxx something. I had a recollection that there were different types of integers (took a little ANSI C in college), and googled "short integer" to get the value range.

In programming, any number that's a power of 2 tends to stick in your head. Because Artemis 2.x doesn't have a math library and you have a very limited tool set for math functions outside of basic arithmetic, there's been a few mission scripts where I've had to "reinvent the wheel".

Before Thom put in get_numeric_property, I wrote a binary search to find the x/z position for named objects. Start with a box with a corner at (0,0) and the other corner at (65536, 100000), check for object, chop it in half, rinse/repeat. After about 16 iterations, you've got the exact x or z coordinate for an object. 

Later in that script, I added some code for carrying around cargo, and I needed a way to tell which cargo holds were empty and which holds already had stuff in them. I was using powers of 2 to tell which items were in which hold. 0 = empty, 1 = cabbages, 2 = flux capacitors, 4 = warnog, 8 = nostril probes, 16 = etc. But to get the number of the cargo hold, I had to convert powers of 2 into the exponent, so 16 = 2^4, 32 = 2^5, 64=2^6, and so forth. This is easy with a natural log function, but that doesn't exist in Art2.x, so I had to kludge something together with a Taylor series, which was a gawd-awful mess and didn't work right, but I managed to get it close enough that it would work for values 1 through 6. 

Anyway, I'm not sure what RNG Artemis is using for integers, but I can ask Thom about it. 


 



__________________
Call Sign (EF/TSN): Bassellope

Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.