Please add Modulo to S&S Editor Logic Syntax

Moderator: Vic

Post Reply
zgrssd
Posts: 5105
Joined: Tue Jun 09, 2020 1:02 pm

Please add Modulo to S&S Editor Logic Syntax

Post by zgrssd »

The Modulo Operator (% in C#) is one of those Operations where at first you have no idea "what is it even good for?"
And once you realize, you can not live without it.

Code: Select all

Y % X == 0
checks if Y can be divided by X without rest.

The most common example would be to check if a number is even:

Code: Select all

Y % 2 == 0

But you can also do some other usefull stuff like "every 20th Turn":

Code: Select all

ROUND % 20 == 0

I tried to approxmiate it with simple division, but

Code: Select all

3 / 2 == 1
is true. As naturally with Integers, 3/2 rounds down to 1. And 1 == 1
I will have to use a large list of or checks like:

Code: Select all

ROUND == 20 | ROUND == 40 | etc.
DeltaV112
Posts: 74
Joined: Wed Oct 15, 2014 11:27 pm

RE: Please add Modulo to S&S Editor Logic Syntax

Post by DeltaV112 »

Presuming we're using integer division.
X % Y == X - (X / Y * Y)
zgrssd
Posts: 5105
Joined: Tue Jun 09, 2020 1:02 pm

RE: Please add Modulo to S&S Editor Logic Syntax

Post by zgrssd »

ORIGINAL: DeltaV112

Presuming we're using integer division.
X % Y == X - (X / Y * Y)
If the game does any variable pruning, it might just be executed as "X % Y == X - X" Or X % Y == 0.
And I would need to check if it even covers all cases properly mathematically.

Plus either way, it is a pretty huge waste of calculation and excessively verbose code - for something that CPU's have hardware level support for [;)]
zgrssd
Posts: 5105
Joined: Tue Jun 09, 2020 1:02 pm

RE: Please add Modulo to S&S Editor Logic Syntax

Post by zgrssd »

I think I can use story+decision logic for something here, that would also allow catching up with any missed events:

Code: Select all

$dueInstances$
 $triggeredInstances$
 
 # Executed each turn
 if($dueInstances$+1 * 20 >= ROUND)
   $dueInstances$ = $dueInstances$+1
 
 # Then in the actuall event:
 if($dueInstances$ > $triggeredInstances$)
   # Do the event
   $triggeredInstances$ = $triggeredInstances$ +1
Still I would prefer being able to just use "ROUND % 20 == 0".
DeltaV112
Posts: 74
Joined: Wed Oct 15, 2014 11:27 pm

RE: Please add Modulo to S&S Editor Logic Syntax

Post by DeltaV112 »

ORIGINAL: zgrssd
If the game does any variable pruning, it might just be executed as "X % Y == X - X" Or X % Y == 0.
And I would need to check if it even covers all cases properly mathematically.

Plus either way, it is a pretty huge waste of calculation and excessively verbose code - for something that CPU's have hardware level support for [;)]
If the game is doing pruning in this case it's a bug, no matter how you slice it divide then multiply by same value is not equivalent to doing nothing. And in performance terms it's irrelevant- your CPU can demolish math like this, and if this somehow does become a performance bottleneck modern CPU's can recognize idioms like this and change the instruction flow(if this were using a non-custom language the compiler would certainly recognize it).
Post Reply

Return to “Suggestions and Feedback”