0 Vote(s) - 0 Average 1 2 3 4 5 Help Number Multiples Tomsen1410 Unstoppable Joined: Jan 2011 Posts: 875 Reputation: 25 03-29-2011, 19:49 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 .   • Pozzuh Wash behind your ears! Joined: Nov 2010 Posts: 3,713 Reputation: 100 03-29-2011, 20:31 (This post was last modified: 03-29-2011, 20:45 by Pozzuh.) 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; }``` The following 1 user says Thank You to Pozzuh for this post:1 user says Thank You to Pozzuh for this post Tomsen1410 Unstoppable Joined: Jan 2011 Posts: 875 Reputation: 25 03-29-2011, 21:08 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   • SuperNovaAO Administrator Joined: Oct 2010 Posts: 3,021 Reputation: 75 03-29-2011, 22:01 (This post was last modified: 03-29-2011, 22:02 by SuperNovaAO.) try (self.test % 7 == 0) Maybe it works. The following 1 user says Thank You to SuperNovaAO for this post:1 user says Thank You to SuperNovaAO for this post Tomsen1410 Unstoppable Joined: Jan 2011 Posts: 875 Reputation: 25 03-30-2011, 15:50 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?   • Tomsen1410 Unstoppable Joined: Jan 2011 Posts: 875 Reputation: 25 03-30-2011, 19:40 Nobody knows?   • Tomsen1410 Unstoppable Joined: Jan 2011 Posts: 875 Reputation: 25 04-18-2011, 13:14 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 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?   • master131 ItsModder Joined: Nov 2010 Posts: 714 Reputation: 75 04-20-2011, 01:15 % 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) A casual conversation between barata and I about Nukem. The following 1 user says Thank You to master131 for this post:1 user says Thank You to master131 for this post AZUMIKKEL shit before you shower Joined: Nov 2010 Posts: 2,599 Reputation: 66 04-20-2011, 01:27 (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   • Xeonic Recruit Joined: Apr 2011 Posts: 43 Reputation: 1 04-20-2011, 10:38 (This post was last modified: 04-20-2011, 10:41 by Xeonic.) (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 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   •

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

Forum Jump:

Users browsing this thread: 1 Guest(s)