0 Favourites

# How do I ....set text to random created numbers

• 11 posts
• hello all together. i am creating a game and my player has the skill X and as he is doing a job, he is getting random (X*1.2,2.1) and this is going to the global variable "money"...

so i want to create a text which appears that shows how much money he got from this job...like if the random created number X=10*2....i want the text to say "you did 20\$ on this job"...

any help is much apprechiated

• You can use the "random" expression to create a random number:

for example random(10) will generate a floating point random number between 0 to 9 (0.5, 2.0, 7.87, etc.)

if you want only integers use floor( random(N) ) this will generate random integers between 0 to (N-1)

if you need to convert those to text (string) use the str() expression:

str( floor( random(10) ) )

• its not about creating a random number...i have generated the random number but i want this random number to show up as a text...see my player has skills...one of them is called "skill"....and as he does a job he generates money...an the money is generated random...random(skill*1.2,skill*2.1)...and this random number which is created i want to make a text for i know how much money my player made at this job...

• Set text to ...... "you did " & str(money) & "\$ on this job"

• i tried this and it shows me the whole amount of money...starting money PLUS the new generated amount, and it also shows everything non rounded...

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• the non rounded problem is solved but i cant figure out how to set the text to the random generated number

• ? So the money is not what you want to show ? As stated in the question. Refrase the question.

• i want to show the money the player earns on this job event....my starting money is 500....the money earned from the job is a random number...i want to show the random number/random amount of money...to be shown as text....

• Okay, seems that at some point you are adding the money the player earns in the event to the total money the player has. The way you describe it now, it seems more as a small bug. Try to figure out when are you adding the money earned to the total or post a capx so we can help figure it out.

• Got to split the amount of money into two variables. 'PreviousMoney' and 'CurrentMoney'

Current money = PreviousMoney + random earned in this job

PreviousMoney = CurrentMoney (set to at start of a new job)

Then the text displays: "You did " & str(CurrentMoney - PreviousMoney) & "\$ on this job"

And a second text could display: "In total you own '& str(CurrentMoney) & "\$"

• ill give this a try....and after it has displayed the amount of money made i can set previousmoney to currentmoney...wait 1sec. -> variables set value-> previousmoney->currentmoney...

think this should work....thanks 99instances2go

• 11 posts