LUA Scripts, loading and communication

LUA Scripts, loading and communication

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

LUA Scripts, loading and communication

Post by Argh »

Now, before I got a-ranting any more about how I think that LUA could be used to build whole new economic gameplay (and, not coincidentally, get rid of large chunks of code within Spring's main loop, by putting them on outside, customized sync timing tracks where they belong anyhow)....

There are two big issues that have come up, as I thought about these things:

1. LUA scripts must (not kind've, nor sort've, MUST) have ways to be invoked that cannot be shut off, and must be able to be loaded by a game. A game should be able to start LUA scripts when it loads. There simply isn't any other way to go about this.

2. LUA scripts must have a common communication system that can be accessed by "sharing" code, as well as by AIs and other agents. A player should be able to share resources in a LUA-engineered game with other players, through simple means codewise, or we'll lose a major element of team-based strategy, which would be bad. However, we need this to be very flexible in its concept of "sharing"... for example:

A. I have a game where I have built a Ba'alrog. It has a magic (LUA-powered) ability to "strengthen the courage of nearby troops". If I move this mighty beast near a pack of my buddy's Orcs, then I darn well want to "pass" this benefit on to those troops, too!

Here, I want to be able to pass along a shareable "container" that goes to a script that looks for a Ba'alrog near troops, and has logic that says, "if friendly, then your troops nearby get a bonus".

B. In my game, I have not TWO resources, but FOUR. And none of them follow the usual rules for Metal and Energy. I have to make Food with laborers, which I feed to Miners, which produce Coal and Ore, and finally I combine the Coal and Ore to make Metal for my armored hordes... who also occasionally need the other two elements. I want to pass my buddy Food... the system of communication to set that up should be fairly trivial:

Player opens Sharing Menu
Player selects "food" resource
Player selects his buddy
Player selects amount / percentage to give, either immediately or every game "long period" (however that is defined).

So, as a coder, I'd need to build the Sharing Menu (not too painful), then define "food" as a game variable that is tracked through (insert some fairly complicated logic here) every (however many ticks we want between "long periods") and which is "shareable". Every "long period", the logic runs, and all of the resource that I have left up to the amount I've designated should then go to the person I've shared with.

Etc., etc.

This means of communication should also provide a portal whereby AIs can "see" new resources, be "told" some things how they work (ok, we're getting into devilishly nasty stuff here, but meh, I'm an idealist) and then actually make use of these things. So AIs can "see" these things because they are a "shareable" item that's defined in a way that AIs can "see", and while they may not handle what to do with this properly, they aren't blind.

The same goes for commands using LUA exclusively, which I predict are going to become more and more popular as people finally get into things. If I have an Engineer unit that can build a Forge, and that Forge can be "upgraded" into an Uber-Forge, and that Uber-Forge then makes, oh, I dunno, "Widgets +3" that are really useful... AIs need a way to be told, "hey, stupid AI! If you can, you should try activating this command under certain circumstances!". And, frankly, this should probably be a common system that all AIs use, instead of the collection of custom hacks that we now have, or it will just be a huge mess and every large game team will need an AI programmer or they'll never have any single-player at all :cry:

So... back on point... what I see coming, once we all get our heads wrapped around this LUA thing, is pretty neato, because we can just about totally abandon OTA if we feel like it... but to get that last inch, frankly, is probably going to be as much work as the first 9.999 miles. But it will be worth it, if we can get this to work, because then, among other things, AI developers will finally have the makings of a core meta-language that goes beyond hard-coded commands.

Why am I bothering with this? Do I write AIs? No. Heck, other than minor goofing around, I hardly know what to do with the LUA thingy yet. But I can already see that there are many, many, many contingencies that AI developers simply cannot handle very well without a better way to see what they need their AIs to do. For example... I used a few tricks in my current project where there are transports that cannot use their weapons unless they are "manned". No AI I've looked at knows how handle this little wrinkle, and since the said transports are, if you just look at stats, not-too-shabby as vehicles, AIs build them and send them at me... empty ;) I'd like to see a future where AIs could be "told" by a game designer, "hey, don't build this unit unless you are using it as a transport", etc., or at the very least, some way to lock AIs OUT of using the unit until they are finally "smart" enough to make use of it properly. The examples of this are just going to keep coming, so it's best to see that future and plan for it, imo.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Ok, since nobody is replying (I assume all of this is taking awhile to digest, not that it's being ignored, lol) here's one thing that has come to mind:

LUA can be invoked by COB. Therefore, the Create() sequences for the Commanders can start LUA scripts that users may not turn off (simply because there won't be any UI function to do so).

So, in theory, we can use that simple method to build custom LUA that runs when a mod starts that invokes some very complex behaviors, all hidden from the user. Note, I'm not saying, "protected" from the user- there's no way to keep them from cheating by hacking memory addresses or whatever- but the average user is basically going to just see some neato gameplay invoked via script.

However, without communication between clients via LUA, this leads to all kinds of problems.

For example... what if we want to use LUA to make it so that two Races, if Allied, get a bonus or penalty for working together? Yeah, I know, this is a somewhat-spurious case (and probably very bad game design), but it's an example ;) If these scripts cannot communicate with one another, i.e., "Hey, we're Allies! Wow... you're Peanut Butter... and I'm Chocolate! We get a bonus!" (sorry in advance, non-native English readers, that was a very American joke)... then they aren't going to be able to do this sort of gameplay (not to mention setting up initial resource balance based on the number of players on each side, and other fun tricks that might be possible with this code- really, the fundamental gameplay uses are pretty neato...
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Or you could use a lua mod gadget and get the same result without any of the issues.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Post by Argh »

Will the mod gadget communicate between players?
trepan
Former Engine Dev
Posts: 1200
Joined: 17 Nov 2005, 00:52

Post by trepan »

The LuaCob, LuaGaia, and LuaRules scripts are primarily 'synced' scripts
(they do have a protected unsynced environment that can be used for GL
drawing, unit selections, etc...)
User avatar
LathanStanley
Posts: 1429
Joined: 20 Jun 2005, 05:16

Post by LathanStanley »

Argh, this is a nifty idea, its complications with LUA are beyond my scope of ability, I've read your posts, there isn't much I can contribute, really (code or advice wise)...
but, I just wanted to point (namely because I work in the steel industry in RL) that you want to mix Iron and Coal to make "steel" :P then you add all kinda alloys like titanium, chromium, nickel, lead, manganeze, silicon, tungsten, and about 14 other elements... (I should go bork some MTR's from the shop and send some specs your direction... it would make for good "upgrades" that you could implement with LUA)

but yeah, its an interesting thought, and I'm all ++++ gung ho for permanent scripts being loaded on map load.

and I'm even more for scripts of units that benefit other units nearby or whatever.. :wink:
Post Reply

Return to “Lua Scripts”