SphereCommunity
How to compare random values - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: How to compare random values (/Thread-How-to-compare-random-values)

Pages: 1 2


How to compare random values - kn4tseb - 06-17-2014 01:28 PM

hey fellas, im going right to the point because i'm pretty sure u know me for the amount of questions i ve done and still have xd...
well here it is.

if x = <r20> | y = <r50>

how can i compare both to get a constant value

x + y = 20

and if i want to make a condition under this, should i use a while?

while (<eval x+y>==20)
dosomething
endwhile

Thank you very much


RE: How to compare random values - XuN - 06-17-2014 05:58 PM

local.x=<r20> // here you set the random numbers
local.y=<r50>

if (<local.x> == 20 || <local.y> == 50)// I don't exactly understand what do you want, however here you have some examples.
if ( <local.x> == <local.y> )
if / while ( <local.x> + <local.y> == 20)

Using a while means that you have to run a code while you have that result, so if you don't want 20 as result and you are changing the values inside the while to get a different result then its ok, otherwise you'll be creating an infinite loop.

Correct
Code:
local.x=<r20>
local.y=<r50>

while (<local.x>+<local.y> == 20 ) <-- this will ensure that you'll have checks untill their sum != 20
local.x=<r20>
local.y=<r50>
endwhile
...
your code

wrong
Code:
local.x=<r20>
local.y=<r50>
while (<local.x>+<local.y>==20) <-- this will create a loop when the result is 20
your code //but if you run your code here without modifying the values ... it will then run forever, hence freezing the server.
end



RE: How to compare random values - kn4tseb - 06-18-2014 12:05 AM

ohhh so while stops till it gets a false result, i need the opposite xddd
i need to make a loop until local.x + local.y == 20 <--------- is TRUE
but chances are low Confused

if i want player A and player B to get 20 Gold total but shared out randomly, so A can get 1 and B 19
or viceversa or A get 5 and B 15, but always 20 as total, do you understand what i mean?

thanks ^^


RE: How to compare random values - Seron - 06-18-2014 12:50 AM

You could do it like this

Code:
local.x=<eval Rand(0,20)>
local.y=<eval 20-<local.x>>

Give Player A <local.x> Gold (which would be random number between 0-20)
and give Player B <local.y> Gold (which would be what ever is left).


Re: How to compare random values - Extreme - 06-18-2014 02:14 AM

LOCAL.X <R20>
LOCAL.Y <R50>
WHILE <EVAL <LOCAL.X>+<LOCAL.Y>> != 20
LOCAL.X <R20>
LOCAL.Y <R50>
ENDWHILE
YOUR_CODE_HERE

But remember, it can loop forever and freeze your sphere.


RE: How to compare random values - Coruja - 06-18-2014 02:21 AM

if you want always 20 as result, it's best use only 1 random value as Seron said
the other value will automatically be the difference between [20 - this random number]
no IF or WHILE is required to do this

Code:
LOCAL.A=<R20>
LOCAL.B=<eval 20-<LOCAL.A>>
REF1.NEWGOLD <LOCAL.A>  //give gold to player A
REF2.NEWGOLD <LOCAL.B>  //give gold to player B



RE: How to compare random values - kn4tseb - 06-18-2014 02:42 AM

understood, i will try, thank you guys Smile


RE: How to compare random values - kn4tseb - 06-18-2014 07:22 AM

But what if i add one more variable like a C player
A=<r20>
B=<r20>
C=<r20>

A + B + C = 20


RE: How to compare random values - Skul - 06-18-2014 07:31 AM

you need to divy the gold, somehow find a means of sharing it between the three, an example
Code:
local.a=<eval {1 20}>
local.divy=<eval <eval 20 +-<local.a>> /2>
player.a.newgold <local.a>
player.b.newgold <local.divy>
player.c.newgold <local.divy>



RE: How to compare random values - Extreme - 06-18-2014 07:45 AM

(06-18-2014 07:22 AM)kn4tseb Wrote:  But what if i add one more variable like a C player
A=<r20>
B=<r20>
C=<r20>

A + B + C = 20

Confused
What are you planning to do with it?
You want to split the gold between the players who killed something?
If yes, we can help better... if not:

PHP Code:
LOCAL.<R20>
LOCAL.<R20>
LOCAL.<R20>
WHILE <EVAL <
LOCAL.A>+<LOCAL.B>+<LOCAL.C>> != 20
 LOCAL
.<R20>
 
LOCAL.<R20>
 
LOCAL.<R20>
ENDWHILE
-> 
A+B+C=20
YOUR_CODE_HERE