Author |
Message |
Major
Joined: Sun May 30, 2010 5:30 am Posts: 853 Location: Auckland, NZ
|
Re: Cortex Command Lua Scripting Tutorial
Quote: Code: local varA = 5 local varB = varA
This would make variable "varB" equal to 5. Note how the word "local" was not used when recalling the variable "varA". It does use "local" when recalling variable "VarA". Quote: -- Statement checking if the distance check (variable "local distcheck") is less than 10. If so, then do the action... if distcheck < 30 then
Two different values.
|
Sun Aug 29, 2010 8:03 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Cortex Command Lua Scripting Tutorial
Major, I'm pretty sure what he meant by the first one is that it shouldn't be written out as this: Code: local varB = local varA
|
Sun Aug 29, 2010 8:48 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Cortex Command Lua Scripting Tutorial
Major wrote: Quote: -- Statement checking if the distance check (variable "local distcheck") is less than 10. If so, then do the action... if distcheck < 30 then
Two different values. Yeah fixed. Also, I added another example, which is for a missile. Check it out!
|
Sun Aug 29, 2010 5:29 pm |
|
|
Major
Joined: Sun May 30, 2010 5:30 am Posts: 853 Location: Auckland, NZ
|
Re: Cortex Command Lua Scripting Tutorial
Quote: Major, I'm pretty sure what he meant by the first one is that it shouldn't be written out as this: Code: local varB = local varA Ahh, thanks. Could you add the documentation for functions and properties here, because the wiki is down, please?
|
Mon Aug 30, 2010 8:02 am |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: Cortex Command Lua Scripting Tutorial
Make sure to read every sticky. viewtopic.php?p=364463#p364463
|
Mon Aug 30, 2010 3:10 pm |
|
|
Shook
Joined: Fri Feb 16, 2007 8:43 pm Posts: 1695 Location: AH SHIT FUCK AUGH
|
Re: Cortex Command Lua Scripting Tutorial
Quick question regarding tables; is there any easy way of checking whether something is in a given table? Or do i just have to "brute force" check? (as in, do a secondary for loop that checks every single entry for the variable i'm looking for) It would be supremely useful for making a decent railgun.
|
Fri Dec 03, 2010 2:59 pm |
|
|
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
|
Re: Cortex Command Lua Scripting Tutorial
Shook wrote: Quick question regarding tables; is there any easy way of checking whether something is in a given table? Pretty much anything can be an index in Lua, so you can use a separate table to store and look up the index of the first table. Code: function Create(self) gAct = {} gLookup = {} gAct[1] = self gLookup[self] = 1 end
function Update(self) print(gAct[gLookup[self]]) end
If "self" is not a member of "gAct" the call "gLookup[self]" will return "nil".
|
Fri Dec 03, 2010 3:24 pm |
|
|
adwuga
Joined: Fri Mar 19, 2010 4:14 am Posts: 20
|
Re: Cortex Command Lua Scripting Tutorial
how would I make a statement saying "if any enemy soldier is alive then..." ?
|
Mon Apr 25, 2011 9:07 am |
|
|
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
|
Re: Cortex Command Lua Scripting Tutorial
adwuga wrote: how would I make a statement saying "if any enemy soldier is alive then..." ? Assuming the player is team one: Code: for Act in MovableMan.Actors do if Act.Team ~= Activity.TEAM_1 then -- there are enemies in the scene -- do stuff here break -- stop looping end end
|
Mon Apr 25, 2011 12:27 pm |
|
|
adwuga
Joined: Fri Mar 19, 2010 4:14 am Posts: 20
|
Re: Cortex Command Lua Scripting Tutorial
thanks Abdul Alhazred. another thing(sorry) this is in my mission code. i want the player to kill all enemies and then kill the brain. for some reason it wont work. can someone tell me whats wrong? Code: ----------------------------------------------------------------------------------------- -- Update Activity ----------------------------------------------------------------------------------------- function Battle:UpdateActivity() -- Clear all objective markers, they get re-added each frame self:ClearObjectivePoints();
self:Killcheck(); self:DestroyBrain(); -- Check for defeat conditions self:DoBrainSelection(); self:YSortObjectivePoints(); end ----------------------------------------------------------------------------------------- -- Kill Everyone check ----------------------------------------------------------------------------------------- function Battle:Killcheck() if self.Killcomplete == false then print ("Kill Humans"); else print ("Complete"); end ----------------------------------------------------------------------------------------- -- Kill Everyone ----------------------------------------------------------------------------------------- function Battle:KillHumans() for Act in MovableMan.Actors do if Act.Team ~= Activity.TEAM_1 then self.Killcomplete = false; else self.Killcomplete = true; break -- stop looping end end end ----------------------------------------------------------------------------------------- -- Destroy Brain ----------------------------------------------------------------------------------------- function Battle:DestroyBrain() if self.Killcomplete == true then if MovableMan:IsActor(self.CPUBrain) then self:AddObjectivePoint("Destroy!", self.CPUBrain.AboveHUDPos, Activity.TEAM_1, GameActivity.ARROWDOWN); else self.WinnerTeam = Activity.TEAM_1; ActivityMan:EndActivity(); end end end
|
Mon Apr 25, 2011 9:03 pm |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Cortex Command Lua Scripting Tutorial
Your KillHumans function is not being initiated in the Update function.
|
Mon Apr 25, 2011 9:10 pm |
|
|
adwuga
Joined: Fri Mar 19, 2010 4:14 am Posts: 20
|
Re: Cortex Command Lua Scripting Tutorial
there was something else wrong with it, since it still doesnt work. that prabably did help though so thanks. any other ideas as to what is wrong?
|
Mon Apr 25, 2011 11:09 pm |
|
|
Roast Veg
Data Realms Elite
Joined: Tue May 25, 2010 8:27 pm Posts: 4521 Location: Constant motion
|
Re: Cortex Command Lua Scripting Tutorial
You don't have a DoBrainSelection function.
|
Mon Apr 25, 2011 11:30 pm |
|
|
adwuga
Joined: Fri Mar 19, 2010 4:14 am Posts: 20
|
Re: Cortex Command Lua Scripting Tutorial
that is further down, I didnt want to put my entire script in the post. what doesnt work is the mission objectives. the self:Killcheck(); and self:KillHumans(); dont work, and so self:DestroyBrain(); is never activated, and the mission cant be won. I could take out the kill functions, but I want the objective to be to kill every one, then kill the brain.
|
Tue Apr 26, 2011 3:16 am |
|
|
Abdul Alhazred
DRL Developer
Joined: Tue Aug 11, 2009 5:09 am Posts: 395
|
Re: Cortex Command Lua Scripting Tutorial
Have you looked in the console for errors? KillChek is missing and end, and KillHumans will set self.Killcomplete to true if there are any actors on team one in the scene. Try doing it like this instead: Code: function Battle:KillHumans() self.Killcomplete = true for Act in MovableMan.Actors do if Act.Team ~= Activity.TEAM_1 then self.Killcomplete = false break -- stop looping end end end
|
Tue Apr 26, 2011 6:08 am |
|
|
|