between a number...

Game Editor comments and discussion.

between a number...

Postby BogdansB » Mon Jan 02, 2012 10:09 am

hello,
How can I generate a number for example

if actor a collides with actor b -> variable c(100) minus (between 10 and 15)

so every time they collide, the variable gets 10,11,12,13,14 or 15 lesser...


thanks for now.
BogdansB
 
Posts: 94
Joined: Tue Oct 25, 2011 2:30 pm
Score: 0 Give a positive score

Re: between a number...

Postby schnellboot » Mon Jan 02, 2012 7:53 pm

Code: Select all
c-=10+rand(5);
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: between a number...

Postby lcl » Mon Jan 02, 2012 10:06 pm

schnellboot wrote:
Code: Select all
c-=10+rand(5);

Actually:
Code: Select all
c -= (10 + rand(6));

Because rand() doesn't return the inputted value in maximum case, it returns one less (when we're talking about integers).
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: between a number...

Postby schnellboot » Mon Jan 02, 2012 10:12 pm

lcl wrote:
schnellboot wrote:
Code: Select all
c-=10+rand(5);

Actually:
Code: Select all
c -= (10 + rand(6));

Because rand() doesn't return the inputted value in maximum case, it returns one less (when we're talking about integers).

lol thanks
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: between a number...

Postby skydereign » Mon Jan 02, 2012 10:14 pm

But as a matter of clarity, it may make more sense to you to do this (they accomplish the same thing).
Code: Select all
c -= (10 + round(rand(5)));

That way it is clear that you are adding a random number from 0-5, since evidence by schnellboot's post it makes more sense to want to say 5 for random numbers 0-5. All round does is take the value you pass it and round according to the .5 rule (meaning rand(5) will round from 0-5 instead of being truncated to 0-4).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest