mdgunn Posted August 23, 2015 Share Posted August 23, 2015 I want to change gravity for the world (SetGravity(x,y,x)) by triggering it from an object entity but how do I access the world object created in Main.lua? Or is there a different way to do this? Can you add functions to Main.lua that you then call from other entities? I'm confused about the change to Main.lua and how it compares to how things used to be with App.lua. Is there a post somewhere that went through the change to Main.lua? Thanks, Michael Gunn Quote Link to comment Share on other sites More sharing options...
Genebris Posted August 23, 2015 Share Posted August 23, 2015 App.world:SetGravity(x,y,x) When you create a variable in App script like this: self.myVar=1 You can access it from any other script like this: App.myVar=2 Or you can use global vars that can be accessed through any script including App.lua like this myGlobalVar=1 Quote Link to comment Share on other sites More sharing options...
Slastraf Posted August 23, 2015 Share Posted August 23, 2015 Or you could go to your scene tab, select "root" and navigate to gravity, the deafault value is 25 but here you can only change the y value of the gravity Quote Link to comment Share on other sites More sharing options...
mdgunn Posted August 23, 2015 Author Share Posted August 23, 2015 Or you could go to your scene tab, select "root" and navigate to gravity, the deafault value is 25 but here you can only change the y value of the gravity But that would not allow be triggering it in game would it (unless I'm missing what you mean)? Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 23, 2015 Share Posted August 23, 2015 http://www.leadwerks.com/werkspace/topic/12579-setgravity-does-not-work-anymore/#entry90604 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
mdgunn Posted August 23, 2015 Author Share Posted August 23, 2015 @Genebris I went with using a global. Personally GLOBALS make me a bit scared. I'd prefer to call a function but I still undertand how you call a function on Main.lua from an entity (or if you can). Anyone know if you can, of are you supposed to go back to the App.lua way to do it? If anyone stumbles accross this later this is how I got gravity change trigger working I added this into Main.lua --Handle Y Gravity change if changeYGravity~=nil then --System:Print("changegravity = "..tostring(changeYGravity)) world:SetGravity(0,changeYGravity,0) changeYGravity = nil end And I created a script called TriggerGravityChange.lua like this (modified from map change one - you may need to change it to your needs). --[[ This script will act as a trigger to change the gravity. This is currently triggered by a collision but you may want to have it triggered by some other means. ]]-- -- positive number for Y gravity are UP! Script.YGravity=10--int "Y Gravity" Script.gravityChanged = false function Script:Start() self.enabled=true end function Script:Collision(entity, position, normal, speed) if self.gravityChanged~= true then --System:Print("Change Gravity - new value = "..self.YGravity) changeYGravity=self.YGravity self.gravityChanged= true end end function Script:Enable()--in if self.enabled==false then self.enabled=true self:CallOutputs("Enable") end end function Script:Disable()--in if self.enabled then self.enabled=false self:CallOutputs("Disable") end end Quote Link to comment Share on other sites More sharing options...
mdgunn Posted August 23, 2015 Author Share Posted August 23, 2015 http://www.leadwerks.com/werkspace/topic/12579-setgravity-does-not-work-anymore/#entry90604 Thanks for the warning macklebee. Luckily I am triggering in game and I seem to have got it working OK, though as I mentioned I went with globals though I'd prefer to call a function (on Main.lua) but I think I don't have clear understanding of if I can do this on Main.lua. Anyway working for now. Thanks, Michael Quote Link to comment Share on other sites More sharing options...
Genebris Posted August 23, 2015 Share Posted August 23, 2015 You can call a function inside App.lua from any other script just like you use variables: App:ChangeGravity(value) Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 23, 2015 Share Posted August 23, 2015 You can call a function inside App.lua from any other script just like you use variables: App:ChangeGravity(value) He is not using the old App.lua format but the new Main.lua. But yes he could essentially perform the same by just placing a function inside the Main.lua prior to the main loop. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
mdgunn Posted August 23, 2015 Author Share Posted August 23, 2015 He is not using the old App.lua format but the new Main.lua. But yes he could essentially perform the same by just placing a function inside the Main.lua prior to the main loop. This is the bit I don't yet understand so can someone please supply the syntax for what the function signature looks like when in Main.lua and also the specific syntax to call it from an entity. Thanks, Michael Quote 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.