View unanswered posts | View active topics It is currently Wed Dec 25, 2024 6:43 pm



Reply to topic  [ 44 posts ]  Go to page Previous  1, 2, 3  Next
 Cortex Command Lua Scripting Tutorial 
Author Message
User avatar

Joined: Sun May 30, 2010 5:30 am
Posts: 853
Location: Auckland, NZ
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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
Profile
User avatar

Joined: Sun May 30, 2010 5:30 am
Posts: 853
Location: Auckland, NZ
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Cortex Command Lua Scripting Tutorial
Make sure to read every sticky.
viewtopic.php?p=364463#p364463


Mon Aug 30, 2010 3:10 pm
Profile WWW
User avatar

Joined: Fri Feb 16, 2007 8:43 pm
Posts: 1695
Location: AH SHIT FUCK AUGH
Reply with quote
Post 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
Profile WWW
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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
Profile

Joined: Fri Mar 19, 2010 4:14 am
Posts: 20
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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
Profile

Joined: Fri Mar 19, 2010 4:14 am
Posts: 20
Reply with quote
Post 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
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Cortex Command Lua Scripting Tutorial
Your KillHumans function is not being initiated in the Update function.


Mon Apr 25, 2011 9:10 pm
Profile

Joined: Fri Mar 19, 2010 4:14 am
Posts: 20
Reply with quote
Post 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
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Cortex Command Lua Scripting Tutorial
You don't have a DoBrainSelection function.


Mon Apr 25, 2011 11:30 pm
Profile

Joined: Fri Mar 19, 2010 4:14 am
Posts: 20
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 44 posts ]  Go to page Previous  1, 2, 3  Next

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.096s | 14 Queries | GZIP : Off ]