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> wrong Code: local.x=<r20> 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 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)> 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> RE: How to compare random values - kn4tseb - 06-18-2014 02:42 AM understood, i will try, thank you guys 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}> 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 playerWhat 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.A <R20> |