wildcherrii Posted April 16, 2022 Share Posted April 16, 2022 how to get a neg random number? Math:Random(-10,10) produces error for me Quote Link to comment Share on other sites More sharing options...
Genebris Posted April 16, 2022 Share Posted April 16, 2022 I don't know why it produces and error, but you can always use the good old classic way: Math:Random(0,20) -10 Also, this is Leadwerks API method and Lua has it's own math.random Might be different, IDK. Quote Link to comment Share on other sites More sharing options...
wildcherrii Posted April 16, 2022 Author Share Posted April 16, 2022 I got a pivot in the world , I've attached a script to it, emit.lua function Script:Start() --small box self.box=Model:Box() end function Script:UpdateWorld() self.MonitorBox() end Function Script:MonitorBox() self.box:Turn(0,1,0) end ------------------------------------------------------------------------------------- Please for the love of God, explain to me why this returns a " attempt to index field "box" a nil value. Is it perhaps because Im using a custom named function? Am i not allowed to make a function ? hrmmmp Lua is such a ball slap, its horrible. Nothing ever happens twice the same way, constantly having to restructure functions or globals to get them to pick up elsewhere, then hope you don't break the entire code by changing the order to much.. blah blah.. Quote Link to comment Share on other sites More sharing options...
reepblue Posted April 17, 2022 Share Posted April 17, 2022 This code should be safer. You also had a capital F for your custom function but that could have been due to auto correct. Script.box = nil function Script:Start() --small box self.box=Model:Box() end function Script:UpdateWorld() self:MonitorBox() end function Script:MonitorBox() if (self.box ~= nil) then self.box:Turn(0,1,0) end end I also don't like Lua because everything can be running fine until a random function triggers and crashes the app. This is one of the reasons I use C++. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted April 17, 2022 Share Posted April 17, 2022 If you call a function like this in Lua it passes one argument to the function: o.function(1) If you call a function with a colon instead (:) it passes the object itself as an argument called self:, plus the other argument for the number one o:function(1) It's like the difference in C++ between a class method and static function. Here is your working code: function Script:Start() self.box=Model:Box() end function Script:UpdateWorld() self:MonitorBox() end function Script:MonitorBox() self.box:Turn(0,1,0) end Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.