• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Number Multiples
#1
Hi,
I have a Problem:
I want to set up, when a variable self.Test is for Example 7,14,21,28,35 ...
return true.
But how can i do this?
I dont want to code 500 IFs for each number.
Only one for 7 and his multiples.
Hope I explained it good...my english isnt the best
How can i do this?
Thx . Smile
  Reply
#2
Code:
is7(number)
{
    for(i=0;i<500;i++)
    {
        number2 = number / 7.0;
        if(number2 == i) return true;
    }
    
    return false;
}

Untested

Edit:
Maybe better
Code:
is7(number)
{
    number = number / 7.0;
    number += ""; //string
    if(IsSubStr( number, ".") && !IsSubStr(number,".0")) return false;
    return true;
}
[Image: MaEIQ.png]
[-] The following 1 user says Thank You to Pozzuh for this post:
  • Tomsen1410
  Reply
#3
Thx, but if I have 2 AND 4 for example, then it wont work cause every multiple of 4 is a multiple of 2 too. i need a 100 % sure function. cause i need it with more numbers.
but thx Wink
  Reply
#4
try (self.test % 7 == 0)

Maybe it works.
[-] The following 1 user says Thank You to SuperNovaAO for this post:
  • Tomsen1410
  Reply
#5
Ok, better idea. cause 2 is automaticly a multiple of EVERY 4 multiple, so better question:

when I have defined a variable self.Test and i want to say
IF (self.Test == blabla){ do thisshit();}
for example:

PHP Code:
if (self.Test == 1){ do thread 1}
else if (
self.Test == 2){ do thread 2}
else if (
self.Test == 3){ do thread 3}
else if (
self.Test == 4){ do thread 4}
else if (
self.Test == 5){ do thread 5

BUT:
how can i say to continue the "loop" of if clauses?
i mean: if self.Test == 6 do thread 1 again or if self.Test == 9do thread 4 again?

How can i code this without using 5 000 000 IFs?
  Reply
#6
Nobody knows?
  Reply
#7
Ok, i wanted to do it like this:
for example i have 3 functions.
when
self.test = 1 do func 1
self.test = 2 do func 2
...

SO
now i did that

if(self.test % 1 == 3)
{do function 1}
if(self.test % 2 == 3)
...
with that it should always do the function one when self.test is 1,4,7,...
but it doesnt works Sad
this function isnt wrking with every number.
when i do
if(self.test % 7 == 5) for example it works ?!
but why it doesnt work with every numbers?
  Reply
#8
% is the modulus operator. It gets the remainder when you divide a number by the other.
5 % 2 = 1 (5 divided by 2 has a remainder of 1)
[Image: 30xhrep.png]

A casual conversation between barata and I about Nukem.
[-] The following 1 user says Thank You to master131 for this post:
  • Tomsen1410
  Reply
#9
(04-20-2011, 01:15)master131 Wrote: % is the modulus operator. It gets the remainder when you divide a number by the other.
5 % 2 = 1 (5 divided by 2 has a remainder of 1)

So it rounds the number down and calculates the amount it rounded down?

So 8/3 would be 2,(2/3). 0,(2/3)*3 = 2 ?



I wonder what this would ever be handy for.
YouTube 1: Azumikkel - Modding
YouTube 2: DerpShark - Gaming Entertainment
Website: Jensby.me
Contact: im[at]jensby.me
  Reply
#10
(04-20-2011, 01:27)AZUMIKKEL Wrote:
(04-20-2011, 01:15)master131 Wrote: % is the modulus operator. It gets the remainder when you divide a number by the other.
5 % 2 = 1 (5 divided by 2 has a remainder of 1)

So it rounds the number down and calculates the amount it rounded down?

So 8/3 would be 2,(2/3). 0,(2/3)*3 = 2 ?



I wonder what this would ever be handy for.
I just record the remainder when you divide a number, and you can put it into any variable or if/while/for statement

(04-18-2011, 13:14)Tomsen1410 Wrote: Ok, i wanted to do it like this:
for example i have 3 functions.
when
self.test = 1 do func 1
self.test = 2 do func 2
...

SO
now i did that

if(self.test % 1 == 3)
{do function 1}
if(self.test % 2 == 3)
...
with that it should always do the function one when self.test is 1,4,7,...
but it doesnt works Sad
this function isnt wrking with every number.
when i do
if(self.test % 7 == 5) for example it works ?!
but why it doesnt work with every numbers?
I recommend you to use randomint although it is not proper C program, but it is a GSC code
However, the biggest mistake is you are so bad with if statement...
It should be like this:
Code:
if(self.test % 1 == 3)
{do function 1}
else if(self.test % 2 == 3)
...
The best way to hide is to change yourself
[Image: y4gg5v83hj1nukndn6x.jpg]
  Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Your phone number? kokole 10 1,460 01-18-2013, 19:59
Last Post: JariZ
  exceeded maximum number of child1 script variables xplosiff 6 4,252 01-07-2012, 11:46
Last Post: xplosiff
Sad [Request] Weapon Change after certain Number of kills Scripts18 5 1,072 09-17-2011, 13:13
Last Post: Scripts18
  [SOLVED] Removing the xp gain number from medal messages Cyborgking 7 1,599 09-15-2011, 16:05
Last Post: Cyborgking
  [Release] Getting the number after the point Pozzuh 7 1,415 09-01-2011, 18:51
Last Post: SuperNovaAO

Forum Jump:


Users browsing this thread: 1 Guest(s)