Author |
Message |
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Attaching Lua to an object after loading
Say I wanted to make a viral infection. The method of infection doesn't matter. When an actor is infected, he slowly dies, turns into a zombie, or whatever. This is just an example.
I would need a Lua script for that. Basically, I just want to attach a Lua script to an object/actor whenever I want to, in-game. Is this possible?
|
Sat Jun 26, 2010 12:29 am |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Attaching Lua to an object after loading
Yo can't 'attach' a script to an actor/object in-game, because you don't need to. Lua doesn't work that way. You attach your script to your projectile/whatever and have it work on actors/whatever by doing checks and seeing if certain parameters are met.
|
Sat Jun 26, 2010 1:09 am |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: Attaching Lua to an object after loading
MaximDude wrote: Yo can't 'attach' a script to an actor/object in-game, because you don't need to. Lua doesn't work that way. You attach your script to your projectile/whatever and have it work on actors/whatever by doing checks and seeing if certain parameters are met. And then what? What do you do when said projectile dies?
|
Sat Jun 26, 2010 1:41 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Attaching Lua to an object after loading
Code: self.ToDelete = false; self.ToSettle = false; self.PinStrength = 1000;
It shall not die.
|
Sat Jun 26, 2010 1:42 am |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: Attaching Lua to an object after loading
Since I want to make a parasite, what I'll do is make a crab thingy that, upon creation, checks if said particle exists, and, if not, creates it. The particle (An MOPixel) on every update will look through the actors on the screen, and if any actors (that aren't parasites) get too close to a parasite, they are marked by the pixel as "infected". On every update, (or every other, etc.) the pixel will decrement infected actors' health by 1. If it gets at or below zero, another parasite is spawned at the actor's location and, if it isn't already, the actor is gibbed.
Will this setup work?
|
Sat Jun 26, 2010 2:04 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Attaching Lua to an object after loading
Right now it sounds like you need a global script right now instead of multiple local scripts. Is only one MOPixel aloud to exist?
|
Sat Jun 26, 2010 2:07 am |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: Attaching Lua to an object after loading
Lol, what's a global script?
|
Sat Jun 26, 2010 2:11 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Attaching Lua to an object after loading
In programming, there can only be one of something that's global. There can be as many local things. So, if you had a "global" script, it would run all the Lua for whatever. Or you could have many local scripts, where each object has its own individual script. Also, here's a tutorial on scripting in Lua and implementing it in Cortex Command.
|
Sat Jun 26, 2010 2:20 am |
|
|
Awesomeness
Joined: Sat Jun 19, 2010 5:02 pm Posts: 331 Location: Mekkan
|
Re: Attaching Lua to an object after loading
Whoops– I knew what global things were, but I knew them by a different name. In Java, you have static and not static, not global and local. I had never needed global scripts in Lua until now, so I had never encountered it, though I do have some past experience with Lua.
|
Sat Jun 26, 2010 7:51 pm |
|
|
|