View unanswered posts | View active topics It is currently Fri Dec 27, 2024 7:14 am



Reply to topic  [ 6 posts ] 
 Newbie needs a point in the right direction 
Author Message

Joined: Tue Jan 20, 2009 6:13 am
Posts: 2
Reply with quote
Post Newbie needs a point in the right direction
Hey.... i need some help figuring out how to make missions in CC, and have a couple basic questions...

I'm looking at the LUA script in the 'Front lines at menou' mission.
Code:
    self.FightStage = { NOFIGHT = 0, DEFENDING = 1, ATTACK = 2, FIGHTSTAGECOUNT = 3 };

    self.AreaTimer = Timer();
    self.StepTimer = Timer();
    self.SpawnTimer = Timer();
    self.ScreenChange = false;

    self.CurrentFightStage = self.FightStage.NOFIGHT;
    self.CPUBrain = nil;
   self.alarmSounded = false;
   
   self.playerActor = nil;
   self.playerSpawnClear = false;
   self.timer = 0;
   self.WeaponList = {"Dummy Sniper", "Dummy Grenade Launcher", "Dummy Blaster", "Dummy Nailgun", "Dummy Pistol", "Dummy Digger"};
   self.Lives = 7;


i'm pretty sure these lines are declaring variables and lists... but what's the "self." prefix before each line?

and this line at the end
Code:
if not MovableMan:IsActor(self.CPUBrain) and ActivityMan:ActivityRunning() then


MovableMan:isactor will return a zero if the object/actor/whatever, whose number is in the variable "self.cpubrain" doesn't exist?

and activityman:activityRunning() will return a 1 if there is an activity running?


there's not alot of documentation... but once i get a grip on the basics of the CC LUA commands i think i'll be allright. I want to start out with a basic assault scene. A base made in the scene editor, with ai units standing around, and you win when you kill the brain, and lose when you run out of lives... any links to tutorials would be helpful too :grin:


Tue Jan 20, 2009 6:58 am
Profile
User avatar

Joined: Thu Jan 18, 2007 5:16 am
Posts: 397
Location: Back at DRL for a while?
Reply with quote
Post Re: Newbie needs a point in the right direction
First off, Lua, not LUA. I'll save you the hate mail from all the other members who worship the Accuracy God. They'll rip you to shreds for doing this.

Now on to your questions:

"self. "
Lua is Object Oriented (referred to as OO, when talking about a language as a whole, it is a language in which OOP [object oriented programming] is possible). "self.foo" is either a variable or a function of an object, the basic part of any object oriented programming language; "self" is the name of the object and "foo" is one of the object's attributes (basically a variable) or a function of the object. One of the main tenets of OO is a characteristic called "inheritance," which allows many "instances" ("living, breathing objects") of a class to gain attributes common to that class. Putting it into every day language, we'll compare these idea to dogs. Dog would be a class, while Lassie would be an object. Dogs, according to our classification, tend to satisfy a couple basic requirements: they are quadrupeds, they have fur, they have a long muzzle, they have long teeth, they usually have a tail and usually have paws. Dogs "inherit" these characteristics as a result of their being classified as "dogs." Now, specific types of dogs obviously have specific attributes. Lassie may have a Breed = Border Collie, while Rover may have a Breed = Bulldog. But they still both have fur, a long muzzle, long teeth, a tail, paws and walk on four legs. This is the advantage of OOP: you don't have to keep calling a "dog" a "dog" over and over again. You can define a class ("actor") which has large amount of shared attributes (note: these are fictional: "HasHealthPoints, HasHands, HasFeet") and then proceed to define specific types of objects ("CoalitionClone, Zombie, Brainbot") from that class.

In this case, the "self" object refers to whatever the object is, be it an actor, a scene, or otherwise (looks like its an actor in this case). Thus, the "self" object allows you to modify the attributes of the actor without typing "MoveableMan(Moveable Manager, a class which defines things like actors).Actor(another class).SomeActorObjectHere.attribute/method" every time. It's basically shortening the coding process for you.

I could go on and on about OOP, even with my superficial understanding of it. This is also entirely based on OO in general and not Lua or Cortex Command specifically, so if you see any factual errors, feel free to correct me. OO is extremely hard to wrap around the mind, and if you're interested in learning about it, I recommend an excellent PHP tutorial on it, even if you don't program in PHP. It gives you a good understanding of what OO is and how you might use it:
http://www.killerphp.com/tutorials/object-oriented-php/
Wikipedia also has a good, if bombastic and convoluted, page on Object Oriented Programming. It's a bit easier to understand if you have watched the video already

Unfortunately I can't help you much without educated guessing on your second question, but I can figure out a good idea of what it may mean. As you said, there is very little documentation on Cortex Command and its libraries of code (something that seriously needs to be remedied), and I have not coded anything in Lua or Cortex Command. You may want to take this part to Lord Tim, who is a Lua god. It would also help me at least to have a snippet of the rest of the code.

Quote:
MovableMan:isactor will return a zero if the object/actor/whatever, whose number is in the variable "self.cpubrain" doesn't exist?


Taking what we just learned about, self.cpubrain is looking at the actor which the rest of the script is referring to and checking the "cpubrain" variable. This may be set somewhere else in the script, or may be an inherited result of whatever actor is being created (ie: brain-class actors might have this attribute set to 1, while non-brains may have it set to 0). I'm not sure what the purpose of this line may be without having the rest of the code block that this if statement starts. It may be checking to see if the actor the user is currently controlling is a brain (or is considered one by the coder). Notice also the "not" in front of it, which will check to see if the "player is not controlling a brain." Often the best way to figure out code is to put it into human semantics and see if what follows makes sense in the context of the code.

Quote:
and activityman:activityRunning() will return a 1 if there is an activity running?

Sounds about right.

Don't take my word on this last question. Lord Tim would probably have a better answer for you. But I hope I at least covered the basics of OOP for you.


Wed Jan 21, 2009 2:13 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: Newbie needs a point in the right direction
In the case of Cortex Command Lua, self is a variable holding the current activity. It's the equivalent of using ActivityMan:GetActivity(), just shorter. What you can do with self is get information about the current activity, basically.
Basically, what MovableMan:IsActor does is check if the actor is still there. In Cortex Command, if you were to simply check "if self.CPUBrain", there would be errors. Even when an actor is no longer alive or on-screen, it still is technically there. With MovableMan:IsActor, you can check if it is in fact alive and not destroyed or part of terrain. And, as with most boolean values, it will return a boolean value. I'm not positive, but that's usually represented by true or false instead of 1 or 0 in lua.
And for the last one, it's checking if the activity is still running. That way, if it's over (for instance, you're dead or you won) the script doesn't continue. And like MovableMan:IsActor(), it returns a boolean value.
A good way to test functions like this is to go into the console (with the ~ key) and type in the function with no arguments (for instance, MovableMan:IsActor() with nothing between the brackets). The console will then give you an error and spit out the usage of the function. You can also type into the console print(<insert function here>) and it will tell you what its output is.


Wed Jan 21, 2009 3:57 am
Profile WWW

Joined: Tue Jan 20, 2009 6:13 am
Posts: 2
Reply with quote
Post Re: Newbie needs a point in the right direction
Cool, after a look at OOP and some more about Lua, i've made alot of progress figuring it out. The only thing that's annoying, is that the user made functions, and the normal functions (CC specific... i guess that counts as user made) look exactly the same, so it's kind of confusing to see if that function was declared earlier, or not...


Thu Jan 22, 2009 1:19 am
Profile
User avatar

Joined: Sat Jun 27, 2009 7:28 pm
Posts: 67
Reply with quote
Post Re: Newbie needs a point in the right direction
didnt want to start a new thread and i found this thread by searching.
what does

self.FightStage = { NOFIGHT = 0, DEFENDING = 1, ATTACK = 2, FIGHTSTAGECOUNT = 3 };

mean?
thanks


Wed Jul 01, 2009 12:10 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Newbie needs a point in the right direction
It makes a list of the fight stages.
Useful for keeping track of how far the stage is.
Of course you don't need it, but that's standard.


Wed Jul 01, 2009 5:46 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.058s | 14 Queries | GZIP : Off ]