Purpose: to round a uneven integer(int) to a even number based off of the given mod(mod) and using the provided middle integer(mid) to determine if the integer should be incremented positively or negatively.
Variables: -int = Any number. -mod = the modulus number to use. -mid = the value to compare to determine if the function should add or subtract.
cool. very simple, with script documentation just like treyarch's utility functions. can you teach me what the % symbol does again?
It returns the modulo of the division. So for example:
10 % 2 returns 0 (as 10/2=5, not a double/float but an integer) 9 % 2 returns 1 (as 9/2 returns a double/float, 8/2 doesn't. 9-8 = 1, so 1 is the answer)
19 % 4 returns 3 (as 19/4 returns a double/float, 16/4 doens't. 19-16=3, so 3 is the answer)
Bad explaination but it works this way. It'll check how much times the number after the % can be in the number before the %, and it'll return the rest (the number before the % minus the number of the last time the number after % could be inserted)
It returns the modulo of the division. So for example:
10 % 2 returns 0 (as 10/2=5, not a double/float but an integer) 9 % 2 returns 1 (as 9/2 returns a double/float, 8/2 doesn't. 9-8 = 1, so 1 is the answer)
19 % 4 returns 3 (as 19/4 returns a double/float, 16/4 doens't. 19-16=3, so 3 is the answer)
Bad explaination but it works this way. It'll check how much times the number after the % can be in the number before the %, and it'll return the rest (the number before the % minus the number of the last time the number after % could be inserted)
yeah i get it. not really that bad of an explanation. thanks guys for teaching me this, ive been wondering for so long....
I personally don't think its necessary to check for all input cases just so the function would work or return if the person couldn't be bothered to check the function args.
Haha ya, nothing like using keywords as your own variables.
To my knowledge, int is not a keyword in GSC. The reason its highlighted in the code box is probably because its set to highlight C language keywords, which GSC is based off of.
To my knowledge, int is not a keyword in GSC. The reason its highlighted in the code box is probably because its set to highlight C language keywords, which GSC is based off of.
You would be correct, but it is still bad practice to do so.
You would be correct, but it is still bad practice to do so.
First off, what is consider 'bad practice'(aka Coding conventions) depends entirely on the language. GSC != C(or other languages) and therefor may not abide by the same 'practices'. Especially since GSC is so straightforward and doesn't even need you to declare what a variable type actually is before using it, which most languages require.
Secondly, with Leviathan released in the state that it was, like if conditions using undefined variables, who are you to question what is or isn't 'good practice'? And don't even try to say running code on undefined variables is OK in any shape or form. World at War in developer mode practically screams 'YOU SHOULDN'T BE RUNNING CODE ON UNDEFINED VARIABLES' every other developer error on Leviathan.
Woah dude, why are you attacking Leviathan? Why would you run it in developer mode in the first place? I couldn't care less what happens in developer mode as long as it runs fine for everyone - besides Awesome Pieman did the majority of scripting for Leviathan and he doesn't know proper scripting practices since he is self taught.
I would also like to counter your argument with why would Treyarch allow you to use undefined variables in the first place (ie the isDefined function, which is quite handy) without them actually working.
Last Edit: October 04, 2015, 06:07:55 am by JBird632
Because its a good example(or the scripts it uses rather).
Quote
I couldn't care less what happens in developer mode as long as it runs fine for everyone
My car makes a bunch of funny noises but it runs!
Alright that was a bit dickheadish, but really just because you are given the option to ignore script screwups doesn't mean you should. While many of World at War's developer errors might seem trivial, they do matter. For instance, if for whatever reason, a function isn't able to delete the zombie's glowing eye model thing because the way the code tried to get the model returned undefined, developer WILL point that out.
Quote
e - besides Awesome Pieman did the majority of scripting for Leviathan and he doesn't know proper scripting practices since he is self taught.
So was i. When i started out i didn't even know what a integer, boolean, double, etc was let alone running code on specific players but eventually i learned about developer which made debugging almost painless(in SP anyway).
Quote
I would also like to counter your argument with why would Treyarch allow you to use undefined variables in the first place (ie the isDefined function, which is quite handy) without them actually working.
If i had to guess it was due to keeping the language as simple and straightforward as possible.
Only recently found out about modulus in JS while learning it, didn't know you could use it in GSC, cool none the less, I know I some people will have good use for this.