This may sound like a stupid question, something that could be as simple as a ‘require ()’ statement (or I’m just too tired
). I’ve been trying to examine and copy your sample “Localizations” to include those SSK declarations, but I am getting the above (title) error on ANY call to a math2d functions.
The other functions work like a charm, except when i make a call to any math2d function. Sorry, what did I miss (or just so stupid to not notice the problem) ?
SSK Version: 2017.007
Corona: 2992
Win 7 Ultimate
Error on Simulator
Thanks
I really need to see your code, but this is generally the way I localize math functions in a module …
-
Follow these directions to add ssk2 to your main.lua file: https://roaminggamer.github.io/RGDocs/pages/SSK2/#installing-ssk2
-
A sample module with math2d localized
– ============================================================= – someModule.lua – ============================================================= – ============================================================= – Localizations – ============================================================= – -- SSK 2D Math Library local addVec = ssk.math2d.add;local subVec = ssk.math2d.sub;local diffVec = ssk.math2d.diff local lenVec = ssk.math2d.length;local len2Vec = ssk.math2d.length2; local normVec = ssk.math2d.normalize;local vector2Angle = ssk.math2d.vector2Angle local angle2Vector = ssk.math2d.angle2Vector;local scaleVec = ssk.math2d.scale – ============================================================= – Module Begins – ============================================================= local someModule = {} function someModule.test() local vec = angle2Vector( 45, true ) table.dump(vec) end return someModule
To test it
Then in main.lua you could do this:
local works = require "someModule" works.test()
Hi Ed,
I tried and figured i need to declare the function like this:
local isWithinDistance = ssk.math2d.isWithinDistance
before I can use it, like so:
if isWithinDistance(player.x, player.y, creeper.x, creepers.y, 400) then actions.face( self, { target = player, rate = facing } ) actions.movep.forward( self, { rate = speed } ) else actions.movep.forward( self, { rate = 0 } ) end
I was thinking of simply calling it directly, and did this (and get the error):
if math2d.isWithinDistance(player.x, player.y, creepers[i].x, creepers[i].y, 400) --- error 'math2d' nil
Cheers,
Santi
You’re missing the ssk in every statement you listed…
if isWithinDistance(player.x, player.y, creeper.x, creepers.y, 400) then ssk.actions.face( self, { target = player, rate = facing } ) ssk.actions.movep.forward( self, { rate = speed } ) else ssk.actions.movep.forward( self, { rate = 0 } ) end if ssk.math2d.isWithinDistance(player.x, player.y, creepers[i].x, creepers[i].y, 400)
Note: All of these functions have examples in the docs:
Just remember, everything lives under ssk.*
Precisely!! I just got it figured out :) :) (my bad)
SSK is an awesome piece of work. Minutes after downloading it, I already came up with a game idea with its host of rich functions.
MANY THANKS!!
Santi
You’re welcome. Good luck with your development and happy coding!
I really need to see your code, but this is generally the way I localize math functions in a module …
-
Follow these directions to add ssk2 to your main.lua file: https://roaminggamer.github.io/RGDocs/pages/SSK2/#installing-ssk2
-
A sample module with math2d localized
– ============================================================= – someModule.lua – ============================================================= – ============================================================= – Localizations – ============================================================= – -- SSK 2D Math Library local addVec = ssk.math2d.add;local subVec = ssk.math2d.sub;local diffVec = ssk.math2d.diff local lenVec = ssk.math2d.length;local len2Vec = ssk.math2d.length2; local normVec = ssk.math2d.normalize;local vector2Angle = ssk.math2d.vector2Angle local angle2Vector = ssk.math2d.angle2Vector;local scaleVec = ssk.math2d.scale – ============================================================= – Module Begins – ============================================================= local someModule = {} function someModule.test() local vec = angle2Vector( 45, true ) table.dump(vec) end return someModule
To test it
Then in main.lua you could do this:
local works = require "someModule" works.test()
Hi Ed,
I tried and figured i need to declare the function like this:
local isWithinDistance = ssk.math2d.isWithinDistance
before I can use it, like so:
if isWithinDistance(player.x, player.y, creeper.x, creepers.y, 400) then actions.face( self, { target = player, rate = facing } ) actions.movep.forward( self, { rate = speed } ) else actions.movep.forward( self, { rate = 0 } ) end
I was thinking of simply calling it directly, and did this (and get the error):
if math2d.isWithinDistance(player.x, player.y, creepers[i].x, creepers[i].y, 400) --- error 'math2d' nil
Cheers,
Santi
You’re missing the ssk in every statement you listed…
if isWithinDistance(player.x, player.y, creeper.x, creepers.y, 400) then ssk.actions.face( self, { target = player, rate = facing } ) ssk.actions.movep.forward( self, { rate = speed } ) else ssk.actions.movep.forward( self, { rate = 0 } ) end if ssk.math2d.isWithinDistance(player.x, player.y, creepers[i].x, creepers[i].y, 400)
Note: All of these functions have examples in the docs:
Just remember, everything lives under ssk.*
Precisely!! I just got it figured out :) :) (my bad)
SSK is an awesome piece of work. Minutes after downloading it, I already came up with a game idea with its host of rich functions.
MANY THANKS!!
Santi
You’re welcome. Good luck with your development and happy coding!