Problem with the % symbol

Hi. I was rtying to divide with the % symbol, but so far I hadn't gotten it to work. Do you know how to divide and get the remainder with the % symbol? Does my code work?

My code:

Route 24.divisiblenum = Route 24.count2
Route 24.divisiblenum = Route 24.divisiblenum - 1
Route 24.ideology = Route 24.divisiblenum % 5
if (result = 0) {
  msg ("The number is divisible by 5.")
  firsttime {
    if (roll > 0 and roll < 26) {
      SpawnSentret (Route 24)
    }
    else if (roll > 25 and roll < 51) {
      SpawnHoothoot (Route 24)
    }
    else if (roll > 50 and roll < 76) {
      SpawnSpinarak (Route 24)
    }
  }
  otherwise {
    if (roll > 0 and roll < 21) {
      SpawnSentret (Route 24)
    }
    else if (roll > 20 and roll < 41) {
      SpawnHoothoot (Route 24)
    }
    else if (roll > 40 and roll < 61) {
      SpawnSpinarak (Route 24)
    }
  }
}

(filler for getting my edited post, updated/posted)


factoring/divisibility and odd/even modulus (%) arithmetic operation:

example: only using/checking prime numbers, aside from '2', to make it easy/simple for me

COUNT = GetRandomInt (0,1000)

if (COUNT % 2 = 1) {
  msg ("COUNT is an ODD number/amount")
} else if (COUNT % 2 = 0) {
  msg ("COUNT is an EVEN number/amount")
  msg ("COUNT IS DIVISIBLE BY 2")
} else if (COUNT % 3 = 0) {
  msg ("COUNT IS DIVISIBLE BY 3")
} else if (COUNT % 5 = 0) {
  msg ("COUNT IS DIVISIBLE BY 5")
} else if (COUNT % 7 = 0) {
  msg ("COUNT IS DIVISIBLE BY 7")
} else if (COUNT % 11 = 0) {
  msg ("COUNT IS DIVISIBLE BY 11")
} else if (COUNT % 13 = 0) {
  msg ("COUNT IS DIVISIBLE BY 13")
}
// etc etc etc else ifs

how cyclic modulus (%) arithmetic operation works:

COUNT % MODULUS_VALUE = [0 to MODULUS_VALUE - 1]

00 % 2 = R0 = 0 // EVEN // 0 is divisible by 2
01 % 2 = R1 = 1 // ODD
02 % 2 = R0 = 0 // EVEN // 2 is divisible by 2
03 % 2 = R1 = 1 // ODD
04 % 2 = R0 = 0 // EVEN // 4 is divisible by 2
05 % 2 = R1 = 1 // ODD
06 % 2 = R0 = 0 // EVEN // 6 is divisible by 2
etc etc etc

00 % 3 = R0 = 0 // 0 is divisible by 3
01 % 3 = R1 = 1
02 % 3 = R2 = 2
03 % 3 = R0 = 0 // 3 is divisible by 3
04 % 3 = R1 = 1
05 % 3 = R2 = 2
06 % 3 = R0 = 0 // 6 is divisible by 3
07 % 3 = R1 = 1
08 % 3 = R2 = 2
09 % 3 = R0 = 0 // 9 is divisible by 3
etc etc etc

00 % 4 = R0 = 0 // 0 is divisible by 4
01 % 4 = R1 = 1
02 % 4 = R2 = 2
03 % 4 = R3 = 3
04 % 4 = R0 = 0 // 4 is divisible by 4
05 % 4 = R1 = 1
06 % 4 = R2 = 2
07 % 4 = R3 = 3
08 % 4 = R0 = 0 // 8 is divisible by 4
09 % 4 = R1 = 1
10 % 4 = R2 = 2
11 % 4 = R3 = 3
12 % 4 = R0 = 0 // 12 is divisible by 4
etc etc etc

00 % 5 = R0 = 0 // 0 is divisible by 5
01 % 5 = R1 = 1
02 % 5 = R2 = 2
03 % 5 = R3 = 3
04 % 5 = R4 = 4
05 % 5 = R0 = 0 // 5 is divisible by 5
06 % 5 = R1 = 1
07 % 5 = R2 = 2
08 % 5 = R3 = 3
09 % 5 = R4 = 4
10 % 5 = R0 = 0 // 10 is divisible by 5
11 % 5 = R1 = 1
12 % 5 = R2 = 2
13 % 5 = R3 = 3
14 % 5 = R4 = 4
15 % 5 = R0 = 0 // 15 is divisible by 5

MODULUS 12: such as for civilian hours (am/pm):

00 % 12 = R00 = 00 // 0 is divisible by 12
01 % 12 = R01 = 01
02 % 12 = R02 = 02
03 % 12 = R03 = 03
04 % 12 = R04 = 04
05 % 12 = R05 = 05
06 % 12 = R06 = 06
07 % 12 = R07 = 07
08 % 12 = R08 = 08
09 % 12 = R09 = 09
10 % 12 = R10 = 10
11 % 12 = R11 = 11
12 % 12 = R00 = 00 // 12 is divisible by 12
13 % 12 = R01 = 01
14 % 12 = R02 = 02
15 % 12 = R03 = 03
16 % 12 = R04 = 04
17 % 12 = R05 = 05
18 % 12 = R06 = 06
19 % 12 = R07 = 07
20 % 12 = R08 = 08
21 % 12 = R09 = 09
22 % 12 = R10 = 10
23 % 12 = R11 = 11
24 % 12 = R00 = 00 // 24 is divisible by 12
25 % 12 = R01 = 01

MODULUS 24: such as for military hours:

00 % 24 = R00 = 00 // 0 is divisible by 24
01 % 24 = R01 = 01
02 % 24 = R02 = 02
03 % 24 = R03 = 03
04 % 24 = R04 = 04
05 % 24 = R05 = 05
06 % 24 = R06 = 06
07 % 24 = R07 = 07
08 % 24 = R08 = 08
09 % 24 = R09 = 09
10 % 24 = R10 = 10
11 % 24 = R11 = 11
12 % 24 = R12 = 12
13 % 24 = R13 = 13
14 % 24 = R14 = 14
15 % 24 = R15 = 15
16 % 24 = R16 = 16
17 % 24 = R17 = 17
18 % 24 = R18 = 18
19 % 24 = R19 = 19
20 % 24 = R20 = 20
21 % 24 = R21 = 21
22 % 24 = R22 = 22
23 % 24 = R23 = 23
24 % 24 = R00 = 00 // 24 is divisible by 24
25 % 24 = R01 = 01

MODULUS 60: such as for seconds and minutes:

000 % 60 = R00 = 00 // 0 is divisible by 60
001 % 60 = R01 = 01
(....)
059 % 60 = R59 = 59
060 % 60 = R00 = 00 // 60 is divisible by 60
061 % 60 = R01 = 01
(...)
119 % 60 = R59 = 59
120 % 60 = R00 = 00 // 120 is divisible by 60
121 % 60 = R01 = 01


You have:

Route 24.ideology = Route 24.divisiblenum % 5

Okay, so you're creating a new attribute named ideology which contains 0 if divisiblenum is divisible by 5.
This probably works.

But you don't use ideology anywhere else in your code.

Then you have:

if (result = 0) {

You haven't given result a value, so this will cause an error.

Did you perhaps mean if (Route 24.ideology = 0) {?


@HK: You seem to be using the word modulus when you mean modulo.

The modulo operator (%) finds the modulus (remainder) of a division. The modulus operator is something completely different.


Log in to post a reply.

Support

Forums