SRL Archive - OSR Help

How Do You Mod?


YoHoJo

2013-03-05 17:46:35

    If Tries > 0 And
((Tries Mod 5) = 0) Then LastStep;

How do you mod?
<3
Easy question, but it made for a good thread title hauh?!

x[Warrior]x3500

2013-03-05 17:51:21


writeln(12 mod 5);

edit: it seems like ur doin it right in your code
edit2:


{insert big number} mod {insert small number}

YoHoJo

2013-03-05 17:56:26

My Tries is being inced, so at first it's smaller.
I guess I should do If Tries > 5 then If Tries Mod 5=0 then?
except properly? :p

masterBB

2013-03-05 18:06:14

Works like a charm:
program new;

Var
Tries: Integer;

begin
Tries := 0;

repeat
writeln(Tries);
If ((Tries > 0) And (Tries Mod 5 = 0)) Then
writeln('laststep');

Inc(Tries);
until(Tries = 50);
end.

YoHoJo

2013-03-05 18:32:47

Yeah it was just weird random stuff going wrong.
Dem extra (((())((()()((()(s never hurt, thanks guys
If ((Tries > 0) And (Tries Mod 5 = 0)) Then LastStep;


Repped you masterBB for this and my last help thread, enjoy your extra square!

masterBB

2013-03-05 19:08:46

From: YoHoJo
Yeah it was just weird random stuff going wrong.
Dem extra (((())((()()((()(s never hurt, thanks guys
If ((Tries > 0) And (Tries Mod 5 = 0)) Then LastStep;


Repped you masterBB for this and my last help thread, enjoy your extra square!


Thanks, well for your reputation power I guess I can give an explanation why too. ^^

In pascalscript there is a certain order of calculating equations with different mathematical operators. It doesn't matter in which order you type it, it will just go through this order. An example would be:

[INDENT]10 + 5 * 5[/INDENT]

Where you can clearly see that multiplying is done before adding. This of course equals what you learned at elementary school with Math. Now, it gets interesting when you use mathematical operators you haven't heard of at school. Shr, Shl and Mod are examples. What you might not know is that And is also one of these operators. It is a Bitwise operator, it basically checks for what bits are both 1's.

example:

[INDENT]10 < 19 and (10 mod 8) = 2[/INDENT]

The problem is this. The first thing it will do are the parentheses. So you will get:

[INDENT]10 < 19 and 2 = 2[/INDENT]

The next step will be the And operator since bitwise operators are very high on the list of Mathematical operators. Much higher then < and =, these are actually pretty low on the list. So the next step will be:

[INDENT]10 < 2 = 2[/INDENT]

Now this will give an error in pascalscript, and unexpected results in lape.

Want to know more about bitwise operators? Yakman(there are also some others) wrote a tut about it: http://villavu.com/forum/showthread.php?t=18514