Author Topic: Number Generator For Variables  (Read 2237 times)

0 Members and 1 Guest are viewing this topic.

Number Generator For Variables
So I understand that you can use a random number generator with the sexp random-of. However I am curious if its possible to define a pool of numbers for the generator to pick from?

Context:
I want to add randomness to where certain ships warp in while still controlling there general location. To do this I will have them warp near a placeholder ship (the SJD Sathanas seems its invisible). BUT before they warp I want to manipulate the co-ordinates of the placeholder ship to one of 15 waypoints scattered around. I want the number generator to pick a number between 1-15 which corresponds to each warp location.

Is this possible?
Too many ideas.....not enough FREDing time!

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Number Generator For Variables
Yes, absolutely. random-of takes a list of arguments (in this case, waypoint locations), and returns a random element from that list. Do note, however, that what you actually want is random-multiple-of, since random-of will fire once and then continue to return the same result.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: Number Generator For Variables
That's some PHP-level function naming there.
The good Christian should beware of mathematicians, and all those who make empty prophecies. The danger already exists that the mathematicians have made a covenant with the devil to darken the spirit and to confine man in the bonds of Hell.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Number Generator For Variables
Not by choice. The original rand SEXP had the same behaviour and it would be really confusing if random-of didn't.

You can also just use rand-multiple rather than rand-multiple-of. You can specify that you want a random number between 1 and 15 quite easily.

Random-multple-of requires you to use when-argument. It's probably easier but it depends on you've already FREDded.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

  
Re: Number Generator For Variables
Okay i am a little lost, so if I am going to have 4 instances of random events, should I use random-multiple-of or rand-multiple? Then what is the best way to implement it? I feel either I don't know/understand enough on how to use it or that I haven't created all the variables etc need to set it up.
Too many ideas.....not enough FREDing time!

 

Offline Goober5000

  • HLP Loremaster
  • 214
    • Goober5000 Productions
Re: Number Generator For Variables
If you use a when-argument sexp, use rand-multiple-of.

If you use a regular when sexp, use rand-multiple if it has a repeat count or trigger count, and use regular rand if it does not.

 
Re: Number Generator For Variables
Success, I now have one groups warp point randomly changing every play through. Now to make the other 3 groups events.  :D

Admiral Ralwood's thread "Example Event: Setting cargo at random" proved very helpful in working out how to set it out.
Too many ideas.....not enough FREDing time!

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Number Generator For Variables
Glad it came in handy for someone. :yes:
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.