Data Realms Fan Forums http://45.55.195.193/ |
|
Lua Questions http://45.55.195.193/viewtopic.php?f=73&t=15155 |
Page 1 of 1 |
Author: | DSMK2 [ Wed Jun 03, 2009 8:38 am ] |
Post subject: | Lua Questions |
Since I don't get this language at all, this is my code for the DSTech Gold Generator, what exactly am I doing wrong? Code: function Create(self) --Do nothing :| end function Update(self) Addfunds = 0; while self.isDead == false do Addfunds = ActivityMan:GetActivity():GetTeamFunds(self.Team); ActivityMan:GetActivity():SetTeamFunds(Addfunds+10, 0); end end And does "~=" equals "!="? |
Author: | Geti [ Wed Jun 03, 2009 8:41 am ] |
Post subject: | Re: Lua Questions |
Code: function Create(self) self.Addfunds = 0; end function Update(self) while self.isDead == false do self.Addfunds = ActivityMan:GetActivity():GetTeamFunds(self.Team); ActivityMan:GetActivity():SetTeamFunds( self.Addfunds + 10 ), self.Team); end end edit: also, yes ~= is the lua "does not equal". |
Author: | DSMK2 [ Wed Jun 03, 2009 8:52 am ] |
Post subject: | Re: Lua Questions |
The gold doesn't seem to be incrementing in-game though, should I try switching to timer based? |
Author: | Geti [ Wed Jun 03, 2009 8:55 am ] |
Post subject: | Re: Lua Questions |
yeah, almost certainly. Code: function Create(self) self.Addfunds = 0; self.cashtimer = Timer(); end function Update(self) if self.cashtimer:IsPastSimMS(500) then self.Addfunds = ActivityMan:GetActivity():GetTeamFunds(self.Team); ActivityMan:GetActivity():SetTeamFunds( self.Addfunds + 10 ), self.Team); end end |
Author: | Daman [ Wed Jun 03, 2009 11:28 am ] |
Post subject: | Re: Lua Questions |
DSMK2 wrote: Since I don't get this language at all, this is my code for the DSTech Gold Generator, what exactly am I doing wrong? Code: function Create(self) --Do nothing :| end function Update(self) Addfunds = 0; while self.isDead == false do Addfunds = ActivityMan:GetActivity():GetTeamFunds(self.Team); ActivityMan:GetActivity():SetTeamFunds(Addfunds+10, 0); end end And does "~=" equals "!="? Hey Geti. Stop posting. DSMK, yes, that is what ~= is. Code: function Create(self) --Do nothing :| end function Update(self) Addfunds = 0; while self.isDead == false do Addfunds = ActivityMan:GetActivity():GetTeamFunds(self.Team); ActivityMan:GetActivity():SetTeamFunds(Addfunds+10, 0); Addfunds = Addfunds + 1; end end That really ought to work. You just weren't incrementing Addfunds, so it'd constantly set your gold to 10. Then again, you may want to change SetTeamFunds' second argument, the 0, to self.Team if this is on an actor. That'd guarantee that the actor sets his team's money and not just team 0. But if you're not telling me what error you're getting, I can't really help any more than that. Actually, you really don't need a while loop at all. This would be more proper-- Code: function Create(self) Addfunds = 0; end function Update(self) if self.isDead then return true end Addfunds = ActivityMan:GetActivity():GetTeamFunds(self.Team); ActivityMan:GetActivity():SetTeamFunds(Addfunds+10, 0); end And then when you test that out, you'd probably want to prefix Addfunds with self. as well, so you can have more than one on the field. |
Author: | Geti [ Wed Jun 03, 2009 11:48 am ] |
Post subject: | Re: Lua Questions |
ohkay, with some actual testing, heres code that works. i failed at some unclosed brackets. >_< note to all involved, it makes your money go up pretty fast. Code: function Create(self) self.Addfunds = 0; self.cashtimer = Timer(); end function Update(self) if self.cashtimer:IsPastSimMS(500) then self.Addfunds = ActivityMan:GetActivity():GetTeamFunds(self.Team); ActivityMan:GetActivity():SetTeamFunds( ( self.Addfunds + 10 ), self.Team); self.cashtimer:Reset() end end also, he didnt need to increment addfunds because it was already using the new value grabbed from GetTeamFunds(), which had ten added onto it from last time. |
Author: | DSMK2 [ Wed Jun 03, 2009 1:45 pm ] |
Post subject: | Re: Lua Questions |
Thanks, is there anyway for an object to check distance from ground via lua? For function calls, its: <object name>:<functioname>(); Not like: <object name>.<functionname>(); Right? And I don't need to declare variable types? Not only that, cc only "uses" two functions, create and update? Update is constantly used after the object is created? |
Author: | Geti [ Wed Jun 03, 2009 2:09 pm ] |
Post subject: | Re: Lua Questions |
yeah there is. im using it in the jump code for my zombies. Code: SceneMan:FindAltitude(self.Pos,<MAXIMUM HEIGHT TO CHECK>,<DISTANCE BETWEEN PIXELS WHEN CHECKING>) Code: Vector(X,Y) EDIT: better code for the first code box. i didnt realise this function existed. woot, optimisation Code: self:GetAltitude(<MAXIMUM HEIGHT TO CHECK>,<DISTANCE BETWEEN PIXELS WHEN CHECKING>) |
Author: | Grif [ Wed Jun 03, 2009 3:07 pm ] |
Post subject: | Re: Lua Questions |
Wow I can't believe no one noticed the IsDead was missing capitalization and arguments. |
Author: | Geti [ Wed Jun 03, 2009 3:58 pm ] |
Post subject: | Re: Lua Questions |
you dont need arguments when checking true/false in lua, and a while loop would lock up the game indefinitely. |
Author: | DSMK2 [ Wed Jun 03, 2009 5:54 pm ] |
Post subject: | Re: Lua Questions |
Gah, I'm trying to redo my Cannon SS... With a somewhat crazy recoil-less feature, though I can't figure it out, any help? so far I'm trying this: Code: function Create(self) end function Update(self) if self:IsRecoiled() == true then self:SetRecoil((-1)*self.RecoilForce),self.RecoilOffset,true); end end |
Author: | Daman [ Wed Jun 03, 2009 7:03 pm ] |
Post subject: | Re: Lua Questions |
Grif wrote: Wow I can't believe no one noticed the IsDead was missing capitalization and arguments. I figured it was isDead because I had to edit my post from IsDead after noticing he had isDead in his original code. |
Author: | Geti [ Wed Jun 03, 2009 9:09 pm ] |
Post subject: | Re: Lua Questions |
DSMK2 wrote: so far I'm trying this: |
Author: | Grif [ Thu Jun 04, 2009 1:27 am ] |
Post subject: | Re: Lua Questions |
Geti wrote: you dont need arguments when checking true/false in lua, and a while loop would lock up the game indefinitely. if self:IsDead() == true then You need to specify that there AREN'T arguments. |
Author: | Geti [ Thu Jun 04, 2009 5:04 am ] |
Post subject: | Re: Lua Questions |
i dont see why we're still discussing this, cause the code i posted works. however, he was checking IsDead as a variable, like self.IsDead which funnily enough is also invalid. which would explain why CC didnt lock up and then crash, as is the nature of while loops that are intended to span across separate frames. but whatever, that issue is all sorted. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |