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

Get help using Construct 2

Post » Sun Jul 17, 2016 4:17 pm

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 :)
B
3
Posts: 6
Reputation: 187

Post » Sun Jul 17, 2016 4:41 pm

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) ) )
B
28
S
10
G
10
Posts: 96
Reputation: 6,582

Post » Sun Jul 17, 2016 4:45 pm

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...
B
3
Posts: 6
Reputation: 187

Post » Sun Jul 17, 2016 4:55 pm

Set text to ...... "you did " & str(money) & "$ on this job"
B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912

Post » Sun Jul 17, 2016 5:01 pm

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...
B
3
Posts: 6
Reputation: 187

Post » Sun Jul 17, 2016 5:35 pm

the non rounded problem is solved but i cant figure out how to set the text to the random generated number :(
B
3
Posts: 6
Reputation: 187

Post » Sun Jul 17, 2016 6:01 pm

? So the money is not what you want to show ? As stated in the question. Refrase the question.
B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912

Post » Sun Jul 17, 2016 6:05 pm

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....
B
3
Posts: 6
Reputation: 187

Post » Mon Jul 18, 2016 1:26 am

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.
B
28
S
10
G
10
Posts: 96
Reputation: 6,582

Post » Mon Jul 18, 2016 7:41 am

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) & "$"
B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912

Next

Return to How do I....?

Who is online

Users browsing this forum: bluesun66, plinkie and 6 guests