Help with generating random numbers

For help with creating games using Quest

Moderators: Pertex, Cryophile, Alex, sgreig

Help with generating random numbers

Postby sbangs » Wed Dec 15, 2010 11:48 am

I tried numerous ways to use $rand(1;100)$ in my game, and try to output the value, or get the value assigned to a numeric variable, or a string variable and have not succeeded. I get internal error many times, and I'm sure I'm using it wrong.

Can someone help with an example of how to actually implement this function in the game?

Thanks much,

S
sbangs
 
Posts: 58
Joined: Thu Nov 18, 2010 8:41 pm

Re: Help with generating random numbers

Postby Alex » Wed Dec 15, 2010 2:04 pm

That looks correct to me, can you attach an example ASL file?
User avatar
Alex
Site Admin
 
Posts: 2048
Joined: Fri Jun 27, 2003 11:06 pm
Location: London, UK

Re: Help with generating random numbers

Postby sbangs » Wed Dec 15, 2010 4:27 pm

Thanks Alex, what looks correct could only be $rand(1;100)$

Thats it. What's not correct is what I am doing with that? LOL.

I cant seem to figure out where to put that statement in the game, where it will display the random number?

Ok, i modified the grey goose als file from before. My incorrect use of this function is in the script that will fire when you pick up the bottle. Thanks.
Attachments
Grey Goose.asl
(1.85 KiB) Downloaded 46 times
sbangs
 
Posts: 58
Joined: Thu Nov 18, 2010 8:41 pm

Re: Help with generating random numbers

Postby Alex » Wed Dec 15, 2010 5:45 pm

You're overcomplicating the variable assignment - you're not asking the player to type in a random number, so don't use those commands.

I see you want a variable called "random". Here's how to do it:

- Under the Variables category, choose "Set a numeric variable"
- For numeric variable name, type "random"
- For contents, enter the function: "$rand(1;100)$"

Now your random number is stored in the numeric variable, and you can access it using %random%. So change your final print statement to "Your random number is %random%"
User avatar
Alex
Site Admin
 
Posts: 2048
Joined: Fri Jun 27, 2003 11:06 pm
Location: London, UK

Re: Help with generating random numbers

Postby sbangs » Wed Dec 15, 2010 6:49 pm

Here is what I am doing.

Change the contents of variable "random1" to "$rand(1;100)$"
Print "[SIZE 00]Ur number is %random1%"

When the script fires the print statement is a -37258 number, like the default negative when no value is present, i think.

I also seem to be confused with using $ or # or % on certain variables.
sbangs
 
Posts: 58
Joined: Thu Nov 18, 2010 8:41 pm

Re: Help with generating random numbers

Postby sbangs » Wed Dec 15, 2010 6:51 pm

got it, whoops. I didnt set numeric variable.

Ok, i'm good to go now.

Thanks again for the quick responses.


s
sbangs
 
Posts: 58
Joined: Thu Nov 18, 2010 8:41 pm


Return to Quest Forum

Who is online

Users browsing this forum: jaynabonne and 2 guests