Author |
Message |
DSMK2
Joined: Fri Dec 28, 2007 4:19 am Posts: 1119
|
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 "!="?
|
Wed Jun 03, 2009 8:38 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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 should work. edit: also, yes ~= is the lua "does not equal".
|
Wed Jun 03, 2009 8:41 am |
|
|
DSMK2
Joined: Fri Dec 28, 2007 4:19 am Posts: 1119
|
Re: Lua Questions
The gold doesn't seem to be incrementing in-game though, should I try switching to timer based?
|
Wed Jun 03, 2009 8:52 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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 that one should be a lot better. while loops like that one you had would have locked the game up while they were actually running though, so they should be done away with. i cant believe i missed it before.
|
Wed Jun 03, 2009 8:55 am |
|
|
Daman
Joined: Fri Jan 26, 2007 3:22 am Posts: 1451
|
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.
Last edited by Daman on Wed Jun 03, 2009 12:03 pm, edited 3 times in total.
|
Wed Jun 03, 2009 11:28 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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.
|
Wed Jun 03, 2009 11:48 am |
|
|
DSMK2
Joined: Fri Dec 28, 2007 4:19 am Posts: 1119
|
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?
|
Wed Jun 03, 2009 1:45 pm |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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>) there is also a Destroy(self) function, for when an object is destroyed. and no you dont need to declare variable types, unless you are constructing a vector on top of all that, yes function calls are made with a colon, and variable calls are made with a dot. 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>)
|
Wed Jun 03, 2009 2:09 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Lua Questions
Wow I can't believe no one noticed the IsDead was missing capitalization and arguments.
|
Wed Jun 03, 2009 3:07 pm |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: Lua Questions
you dont need arguments when checking true/false in lua, and a while loop would lock up the game indefinitely.
|
Wed Jun 03, 2009 3:58 pm |
|
|
DSMK2
Joined: Fri Dec 28, 2007 4:19 am Posts: 1119
|
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
|
Wed Jun 03, 2009 5:54 pm |
|
|
Daman
Joined: Fri Jan 26, 2007 3:22 am Posts: 1451
|
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.
|
Wed Jun 03, 2009 7:03 pm |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
Re: Lua Questions
DSMK2 wrote: so far I'm trying this: on what, the HDFirearm? wont work unless its just lying on the ground, cause they're treated as attachables when an actor is holding them and scripts are (for some reason) disabled on attachables for the moment..
|
Wed Jun 03, 2009 9:09 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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.
|
Thu Jun 04, 2009 1:27 am |
|
|
Geti
Joined: Sun Jul 13, 2008 9:57 am Posts: 4886 Location: some compy
|
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.
|
Thu Jun 04, 2009 5:04 am |
|
|
|