• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Random Draw Text

A

Aquil roberts

Guest
I'm trying to display a random text message once an object is created. I have this in its "create" eventt.

var randS = random(2);

switch (randS)
{
case 0:
draw_text(view_wview[0]/2,70,"Scripture 0.");
break;
case 1:
draw_text(view_wview[0]/2,70,"Scripture 1..");
break;
case 2:
draw_text(view_wview[0]/2,70,"Scripture 2...");
break;
}



Its not working and I don't know what I'm missing.
 
can't draw (or rather shouldn't try to draw) anything in the create event. Put your drawing code in a draw event.

So what I would do is adjust that switch statement so that it assigns the text to a variable. And then in a draw event, draw the text contained in that variable.
 
Also, random(2) will give you any number between 0 and 2, including decimals.. So, use something like round(random(2)). That will return either 0, 1, or 2.
 

Jakylgamer

Member
this is how i would go about it

create event :
Code:
randS = irandom(2);//use irandom() it chooses whole numbers

switch (randS)
{
case 0:
  rand_text = "Scripture 0.";
break;
case 1:
  rand_text = "Scripture 1.."
break;
case 2:
  rand_text = "Scripture 2...";
break;
}
edit:
also without a case you can do
rand_text = choose("text1", "text2","text3"); for smaller text being shown

draw event :
Code:
draw_text(view_wview[0]/2,70,rand_text);
 
S

SyntaxError

Guest
Wouldn't choose() be better?
Code:
/// Create event.
text = choose("Scripture 0", "Scripture 1", "Scripture 2");

/// Draw event.
draw_text(view_wview[0]/2,70,text);
And you simply can't use any draw_* function in a non-draw event.

There is exceptions to drawing to surfaces in non-draw events, but as the manual states, you still shouldn't do that.
 
Top