The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compare random values
Author Message
kn4tseb
Master
**

Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0



Post: #1
How to compare random values
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
06-17-2014 01:28 PM
Find all posts by this user Like Post Quote this message in a reply
XuN
Sphere Developer
*****

Posts: 852
Likes Given: 102
Likes Received: 156 in 119 posts
Joined: Jul 2013
Reputation: 30



Post: #2
RE: How to compare random values
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
06-17-2014 05:58 PM
Find all posts by this user Like Post Quote this message in a reply
kn4tseb
Master
**

Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0



Post: #3
RE: How to compare random values
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 ^^
(This post was last modified: 06-18-2014 12:15 AM by kn4tseb.)
06-18-2014 12:05 AM
Find all posts by this user Like Post Quote this message in a reply
Seron
Apprentice
*

Posts: 11
Likes Given: 0
Likes Received: 1 in 1 posts
Joined: Jan 2013
Reputation: 0

Motoi

Post: #4
RE: How to compare random values
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).
(This post was last modified: 06-18-2014 12:50 AM by Seron.)
06-18-2014 12:50 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Extreme
Grandmaster Poster
***

Posts: 1,141
Likes Given: 217
Likes Received: 90 in 77 posts
Joined: May 2012
Reputation: 20

SphereCommunity

Post: #5
Re: How to compare random values
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.

STEPS BEFORE CREATE A THREAD
- Check the revisions log;
- Use the search button and use the keywords of your problem;
- Check the WIKI;
- Create a thread.
06-18-2014 02:14 AM
Find all posts by this user Like Post Quote this message in a reply
Coruja
Sphere Developer
*****

Posts: 987
Likes Given: 5
Likes Received: 226 in 187 posts
Joined: Jul 2012
Reputation: 7

Dimension Shard

Post: #6
RE: How to compare random values
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
06-18-2014 02:21 AM
Find all posts by this user Like Post Quote this message in a reply
kn4tseb
Master
**

Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0



Post: #7
RE: How to compare random values
understood, i will try, thank you guys Smile
06-18-2014 02:42 AM
Find all posts by this user Like Post Quote this message in a reply
kn4tseb
Master
**

Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0



Post: #8
RE: How to compare random values
But what if i add one more variable like a C player
A=<r20>
B=<r20>
C=<r20>

A + B + C = 20
(This post was last modified: 06-18-2014 07:48 AM by kn4tseb.)
06-18-2014 07:22 AM
Find all posts by this user Like Post Quote this message in a reply
Skul
Master
**

Posts: 413
Likes Given: 0
Likes Received: 19 in 15 posts
Joined: Jun 2012
Reputation: 9



Post: #9
RE: How to compare random values
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>

"I ask a question to the answer I already know."

Marchadium :: http://www.marchadium.ca/ :: Join us!
06-18-2014 07:31 AM
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
Extreme
Grandmaster Poster
***

Posts: 1,141
Likes Given: 217
Likes Received: 90 in 77 posts
Joined: May 2012
Reputation: 20

SphereCommunity

Post: #10
RE: How to compare random values
(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 

STEPS BEFORE CREATE A THREAD
- Check the revisions log;
- Use the search button and use the keywords of your problem;
- Check the WIKI;
- Create a thread.
06-18-2014 07:45 AM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 2 Guest(s)