Page 1 of 1

How do you draw random numbers?

PostPosted: Thu Jan 18, 2007 10:33 pm
by mrdude317
I got game editor recently, and tried to make a simple program that when the spacebar is pressed, a random number appears (like a virtual dice). I put in the action "Script Edit", and put in this:

strcpy(aaa.text, rand(6));

when I try to click 'ok', it comes up with this error:

"Error Line 1: Incompatible types: cannot convert from 'double' to '* const char' "

What am I doing wrong?

PostPosted: Thu Jan 18, 2007 10:56 pm
by Game A Gogo
instead of
Code: Select all
strcpy(aaa.text, rand(6));
, use this
Code: Select all
aaa.textNumber=rand(6);

PostPosted: Thu Jan 18, 2007 10:58 pm
by Novice
You can't use a string function to copy integers.
Use
Code: Select all
textNumber=round(rand(5)+1);


This will get you a round number from 1-6.

EDIT:
You beat me to it Game a Gogo

PostPosted: Thu Jan 18, 2007 11:03 pm
by Game A Gogo
lol, its ok :P but if you don't want to include a zero use something similar to Novice:
Code: Select all
aaa.textNumber=rand(5)+1);

PostPosted: Fri Jan 19, 2007 2:13 am
by morcior
You could use a string function if you wanted...

Code: Select all

sprintf(aaa.text, "%f", rand(6));



and its got benefits, like easily being able to format the number to n decimal places if it is floating-point.

Code: Select all

sprintf(aaa.text, "%.0f", rand(6)); // 0 decimal places


sprintf(aaa.text, "%.2f", rand(6)); // 2 decimal places



PostPosted: Fri Jan 19, 2007 3:18 am
by Sgt. Sparky
:shock: Wow, look at all the many posts. 8) that is neat that there are so many ways to do somthing so simple. :D