Data Realms Fan Forums
http://45.55.195.193/

Attaching Lua to an object after loading
http://45.55.195.193/viewtopic.php?f=1&t=19102
Page 1 of 1

Author:  Awesomeness [ Sat Jun 26, 2010 12:29 am ]
Post subject:  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?

Author:  MaximDude [ Sat Jun 26, 2010 1:09 am ]
Post subject:  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.

Author:  Awesomeness [ Sat Jun 26, 2010 1:41 am ]
Post subject:  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?

Author:  CaveCricket48 [ Sat Jun 26, 2010 1:42 am ]
Post subject:  Re: Attaching Lua to an object after loading

Code:
self.ToDelete = false;
self.ToSettle = false;
self.PinStrength = 1000;

It shall not die.

Author:  Awesomeness [ Sat Jun 26, 2010 2:04 am ]
Post subject:  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?

Author:  CaveCricket48 [ Sat Jun 26, 2010 2:07 am ]
Post subject:  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?

Author:  Awesomeness [ Sat Jun 26, 2010 2:11 am ]
Post subject:  Re: Attaching Lua to an object after loading

Lol, what's a global script?

Author:  CaveCricket48 [ Sat Jun 26, 2010 2:20 am ]
Post subject:  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.

Author:  Awesomeness [ Sat Jun 26, 2010 7:51 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/