Methods with multiple return values


#1

Dear Mad Scientists,
Does SK have a modulus operator? % is already a reserved symbol.

As an alternative, I am trying to use the MathLib.fmod method, it is described as having two return values.
How would I go about accessing the remainder return value? I believe I saw mention of it somewhere, it had to do with binding a variable using : but I am unsure of the syntax.


#2

Yes, it is mod() in the Integer class.

So you would use it like:

1234.mod(100)
// returns 34

The methods in MathLib can also be used though they come from UE4 and might not be as optimized for use with SkookumScript.


#3

Thank you for the reply!
I am a bit embarrassed to have missed that. :sweat_smile:


#4

Though the Integer@mod() is the way to go here, to answer your question about multiple return values, SkookumScript has a mechanism called return arguments that you can read about in the Primer in the docs.

Blueprints and UE4 use references for return values (and SkookumScript can use this too).

The MathLib.fmod() method would be called like this:

!remainder: 0.0 // Initial value to modify in call
!result: MathLib.fmod(1234 100 remainder)
println("remainder: " remainder " result: " result)

and it would print out:

remainder: 34.0 result: 12