View unanswered posts | View active topics It is currently Sun Jan 05, 2025 5:01 am



Reply to topic  [ 9 posts ] 
 Attaching Lua to an object after loading 
Author Message
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post 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
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post 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
Profile
User avatar

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

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post 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
Profile
User avatar

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

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: Attaching Lua to an object after loading
Lol, what's a global script?


Sat Jun 26, 2010 2:11 am
Profile
User avatar

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

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 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.047s | 13 Queries | GZIP : Off ]