GameMaker: Studio

GameMaker: Studio

View Stats:
dead Online Jul 22, 2013 @ 4:59am
So how do 'Chances' work?
After finishing two tutorial projects (excuse me im still noobish) I decided to go ahead and just try making this random application that, simply put, goes through a set of random sentences (I was thinking about using words instead) and display's it via window or drawn in-app depending on the chance relative to it. (I might just make a few images containing such sentences and use the draw function for them)

Just now realizing, I have NO idea how chances work.

I know how to Test Chances between 1 and another number (Control > Questions > Test Chance) but how do you set up those Chances? I've read that you make them in gml, for example:

if chances == x { show_message("Hello World!"); //or whatever/* }

I might try that but I'm still oblivious on it. any help? :S
Last edited by dead Online; Jul 22, 2013 @ 5:04am
< >
Showing 1-4 of 4 comments
Blyxx Jul 22, 2013 @ 5:46am 
The 'test chance' action generates a random number and checks to see if it's less than 1. The range of the random is between 0 and the number you input. So if you input 3, it generates a random between 0 and 3 and if it's less than 1 it evaluates to true. Something like this:

var myRandom = random(3);

if (myRandom < 1)
{
[stuff happens];
}
dead Online Jul 22, 2013 @ 6:42am 
ahhh okay, thanks for explaining the test chance action, I'm guessing that's not what I want since if you have multiple lines that's more than one they all execute at the same time. (unless if there's a way to cut that?)
Last edited by dead Online; Jul 22, 2013 @ 6:42am
Sera Jul 22, 2013 @ 9:34am 
You'd just check different conditions. ie. if you have, say, 6 different outcomes, you'd generate a random number and break it down.

A good way to go about this, possibly:
var MyRandom; MyRandom = round(random(5)); //generates a random number between 0 and 5.

Rounding the number guarantees you'll get one of six possible outcomes (0 counts as an outcome in this case). You can get slightly different results by changing round out for ceil (always round up) or floor (always round down), but in the case of the latter you'd want to use floor(random(6)), which should still always generate an outcome between 0 and 5 (random numbers never entirely hit the cap you put in place).

After that you'd want to use something like a switch statement, and check my syntax here as I'm working from memory:

switch MyRandom { case 0: show_message("Zero."); break; case 1: show_message("One."); break; //Continue on with this until all options you want covered are handled. default: show_message("You broke it."); break; }

What I'm unsure of here is if it needs brackets, but I'm pretty sure that's solid?

Looking up how switch statements work would do you only favors, but for the general gist, the "switch" here is the random number, and what that comes out to (case) determines where things start operating. The break statment tells the program to stop dealing with the switch at that point; not putting in a break can have some interesting results and can be used to your advantage, but generally you'd want one.

An alternative would be a series of ifs and else ifs, but for a situation where one variable can produce a lot of different results, a switch statement is usually your most efficient bet.
Last edited by Sera; Jul 22, 2013 @ 9:35am
dead Online Jul 22, 2013 @ 9:53am 
ahhh duh, I didn't even think about going that way. Rounding does it perfectly, thank you! :D
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: Jul 22, 2013 @ 4:59am
Posts: 4