Data Realms Fan Forums http://45.55.195.193/ |
|
Accessing variables in AI http://45.55.195.193/viewtopic.php?f=1&t=26268 |
Page 1 of 1 |
Author: | Zaneo [ Mon Nov 14, 2011 10:12 pm ] |
Post subject: | Accessing variables in AI |
How would one access variables declared in the AI code. It says that the variable is a nil value, and it can't access it. <DropShipAI.lua> Code: self.searchedForEngines = true local MoObj for i = 1, MovableMan:GetMOIDCount()-1 do if MovableMan:GetRootMOID(i) == self.ID then -- an obj without a parent has ID == RootID MoObj = MovableMan:GetMOFromID(i) if MoObj.PresetName == "Drop Ship Engine A" then self.LeftEngine = ToAEmitter(MoObj) elseif MoObj.PresetName == "Drop Ship Engine B" then self.RightEngine = ToAEmitter(MoObj) end if self.LeftEngine and self.RightEngine then break end end end if not (self.LeftEngine and self.LeftEngine:IsAttached())then ConsoleMan:PrintString("No left Engine") self.LeftEngine = nil end if not (self.RightEngine and self.RightEngine:IsAttached()) then ConsoleMan:PrintString("No right Engine") self.RightEngine = nil end <DropShipDock.lua> Code: function self:EnableEngines (engage) if engage then ConsoleMan:PrintString("Attempting to engage engines") --if self.Ship.LeftEngine then self.Ship.LeftEngine:EnableEmission(true) ConsoleMan:PrintString("Left Engine Engaged") --end --if self.Ship.RightEngine then self.Ship.RightEngine:EnableEmission(true) ConsoleMan:PrintString("Right Engine Engaged") --end else ConsoleMan:PrintString("Attempting to shut down engines") --if self.Ship.LeftEngine then self.Ship.LeftEngine:EnableEmission(false) ConsoleMan:PrintString("Left Engine Disabled") --end --if self.Ship.RightEngine then self.Ship.RightEngine:EnableEmission(false) ConsoleMan:PrintString("Right Engine Disabled") --end end end |
Author: | Roast Veg [ Mon Nov 14, 2011 10:20 pm ] |
Post subject: | Re: Accessing variables in AI |
Variables like this are private, and cannot be accessed by scripts attached to anything other than themselves. This means that you'll have to do a MOID search to find it again. |
Author: | Abdul Alhazred [ Tue Nov 15, 2011 9:45 am ] |
Post subject: | Re: Accessing variables in AI |
I'm sure someone will be able to help you if you post the whole script or even the whole mod, with an explanation of what it is you are trying to do. |
Author: | Zaneo [ Tue Nov 15, 2011 6:38 pm ] |
Post subject: | Re: Accessing variables in AI |
I'm attempting to rewrite the default dropship ai in order to make it crash less. The other idea was to provide more early outs and reduce nesting. The final idea was to decrease the number of check per cycle done, which if the Ai is making better decisions,is easily possible. If i remember correctly a flaw in the original design is it doesn't consider the size of the object it is avoiding. This results in dropships often clipping the thrusters of other dropships, which one might argue is their weakest part. I figured I might as well fix the dropship dock as well but if I can't access variables that makes it a bit annoying as I was trying to set the ship to docking mode. I would rather not check every cycle, or even every nth cycle on the dropship to see if it is within range of a dock. I was hoping to keep that in the dropship dock code and then have, if self.DockingMode = "Docked" then return end, inside the UpdateAI loop of the dropship. |
Author: | Abdul Alhazred [ Wed Nov 16, 2011 10:37 am ] |
Post subject: | Re: Accessing variables in AI |
Communication between objects mostly rely on ugly hacks at the moment. You could for example use an unused property like sharpness or a global variable to communicate what state the dropship is in. |
Author: | Zaneo [ Wed Nov 16, 2011 7:40 pm ] |
Post subject: | Re: Accessing variables in AI |
Could I store it in AIMODE, as self.Ship.AIMODE ="Docking" ? I would have to adjust my code for dealing with the new AIMODE, and setting it back to a valid one once the ship undocks. The dropship would have a if self.AIMODE = "Docking" then return end in the updateAI loop, so no other code would try to access the "invalid" AIMODE, correct? |
Author: | Abdul Alhazred [ Thu Nov 17, 2011 8:23 am ] |
Post subject: | Re: Accessing variables in AI |
Yes, that is a much better idea than using sharpness. AIMode is an integer, so you would have to pick a number outside of the AIMode enumeration. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |