How do you draw random numbers?

Game Editor comments and discussion.

How do you draw random numbers?

Postby mrdude317 » Thu Jan 18, 2007 10:33 pm

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?
mrdude317
 
Posts: 1
Joined: Thu Jan 18, 2007 10:26 pm
Score: 0 Give a positive score

Postby Game A Gogo » Thu Jan 18, 2007 10:56 pm

instead of
Code: Select all
strcpy(aaa.text, rand(6));
, use this
Code: Select all
aaa.textNumber=rand(6);
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby Novice » Thu Jan 18, 2007 10:58 pm

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
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby Game A Gogo » Thu Jan 18, 2007 11:03 pm

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);
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby morcior » Fri Jan 19, 2007 2:13 am

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


morcior
 
Posts: 83
Joined: Fri Jan 12, 2007 12:16 am
Location: UK
Score: 9 Give a positive score

Postby Sgt. Sparky » Fri Jan 19, 2007 3:18 am

:shock: Wow, look at all the many posts. 8) that is neat that there are so many ways to do somthing so simple. :D
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron