Staredit Network > Forums > SC1 Mapping Tools > Topic: LIT - Lua Interpreted Triggers
LIT - Lua Interpreted Triggers
May 21 2014, 7:14 am
By: CecilSunkure  

May 21 2014, 7:14 am CecilSunkure Post #1



Download LIT Here

Lua Interpreted Triggers(LIT) is a Lua library to generate text triggers. Text triggers are usable by SCMDraft 2, and Chkdraft. Lua code is written, and the LIT library of functions and objects allows a user of LIT to generate triggers en masse. LIT is designed to be very easy to setup and use.

LINK TO DOCUMENATION (PDF)

link to source code

Post has been edited 40 time(s), last time on Nov 9 2015, 12:35 pm by CecilSunkure.



None.

May 21 2014, 7:16 am CecilSunkure Post #2



In this thread: please do post any suggestions here, report any bugs, or ask questions if you have any problems. If you can convince me a particular feature request is useful I'll implement it :)

-Reserved

Post has been edited 2 time(s), last time on May 21 2014, 9:18 am by CecilSunkure.



None.

May 21 2014, 9:04 am trgk Post #3



Since trigger generator is already an abstraction, maybe some can add more of them.
- Automatically detect unused units (maybe CHKDraft API?) & assign them variables.
- More than 16 conditions should be supported. ( Using DC or something )
- More than 64 conditions should be supported. ( Using DC or something )
- Method to attach callback to various exceptions.


LIT should be supported by ChkDraft in form of plugin, not its internal implementation.

Post has been edited 1 time(s), last time on May 21 2014, 10:47 am by trgk.



EUD

May 22 2014, 3:01 am sigsaucy Post #4



id like to try this but it seems a bit too intimidating to me, maybe you can post a few examples of how to use it? (including pictures and step by step instructions) I know this would make me much more inclined to try it.




May 22 2014, 3:11 am CecilSunkure Post #5



Quote from sigsaucy
id like to try this but it seems a bit too intimidating to me, maybe you can post a few examples of how to use it? (including pictures and step by step instructions) I know this would make me much more inclined to try it.
Wellllll okay I'll make a video.

Here it is:



Post has been edited 2 time(s), last time on May 22 2014, 3:20 am by CecilSunkure.



None.

May 23 2014, 3:04 pm Sacrieur Post #6

Still Napping

I checked the lua code for actions and couldn't find the one for switches.

Are you not done putting it all together?



None.

May 23 2014, 5:24 pm CecilSunkure Post #7



Quote from Sacrieur
I checked the lua code for actions and couldn't find the one for switches.

Are you not done putting it all together?
Definitely not! This weekend I'll finish more actions :)



None.

May 30 2014, 3:24 pm Sacrieur Post #8

Still Napping

Quote from CecilSunkure
Quote from Sacrieur
I checked the lua code for actions and couldn't find the one for switches.

Are you not done putting it all together?
Definitely not! This weekend I'll finish more actions :)

:massimo:



None.

Jun 1 2014, 10:12 am CecilSunkure Post #9



Ha! Patience :)



None.

Aug 12 2014, 8:56 am CecilSunkure Post #10



All conditions and actions are supported. I've tested them all and should have nearly all bugs found and fixed. Please report any bugs if you do find them. I've decided to host all examples and any LIT tutorial-esque stuff on my own website since it's easier to write and format things there.

There really doesn't need to be much documentation since I've written two huge example files showing how to use each condition and action. If anyone wants to learn to use LIT it's mostly going to be a matter of learning Lua. Luckily learning Lua is a very productive and easy thing to do!

Hopefully I have energy to actually make an example map, and perhaps a short Youtube video of running LIT to generate triggers for a scenario file :) We'll see how much energy I have tomorrow.

Edit: Oh and the first version of LIT was deleted. I didn't really like how I the code was going, so I started over. So Sacruier will need to redownload the files.



None.

Aug 12 2014, 9:03 am trgk Post #11



Syntax looks esoteric.

Code
unit = Unit( )
unit:SetPlayer( Player3 )
unit:SetUnit( "Terran Marine" )
unit:SetCount( 0 )
unit:SetLocation( "Anywhere" )

players:Conditions( )
Always( )
players:Actions( )
unit:Create( )

unit:SetGiveToPlayer( 2 )

players:Conditions( )
Always( )
players:Actions( )
unit:Give( )
unit:Kill( )
unit:KillAt( )

...



I really had to 'parse' this plaintext. Is there any advantages of using these syntax?



EUD

Aug 12 2014, 9:07 am CecilSunkure Post #12



The idea is to separate initialization and trigger generation. Here we see some initialization code just assigning values. The player, unit, location and count (of units) are all set:

Code
unit = Unit( )
unit:SetPlayer( Player3 )
unit:SetUnit( "Terran Marine" )
unit:SetCount( 0 )
unit:SetLocation( "Anywhere" )


After this is done creating a trigger can be done in a readable block of code:

Code
players:Conditions( )
Always( )
players:Actions( )
unit:Create( )


This is nice if you look at the Binary Countoff example I have written:

Code
--  Create a player group for creating triggers
p = PlayerGroup( 1, 2, 3 )

-- Create a death counter
d = Deaths( )
d:SetUnit( "Terran Marine" )
d:SetPlayer( 8 )

-- Create another death counter
d2 = Deaths( )
d2:SetUnit( "Terran Marine" )
d2:SetPlayer( 7 )

-- Generate the binary countoff triggers with a loop
i = 1
exponent = 1
while i < 12 do
 d:SetCount( exponent )
 d2:SetCount( exponent )

 p:Conditions( )
 d:AtLeast( )
 p:Actions( )
 d:Subtract( )
 d2:Add( )

 i = i + 1
 exponent = exponent * 2
end


Since initialization happens in one place, and trigger generation in another, triggers can be generated within a loop in a simple and readable manner.

I hope this makes sense!



None.

Aug 12 2014, 9:14 am trgk Post #13



OK. Building patterned triggers could be quite easy with those semantics.
But building once-used triggers with those syntax seems like a pain.

ex)

CreateUnit(1, "Boss #1", "test", "Player 1") // only used once.

vs

unit = Unit( )
unit:SetPlayer( Player1 )
unit:SetUnit( "Boss #1" )
unit:SetCount( 1 )
unit:SetLocation( "test" )
unit:Create( ) // 6 lines


Some kind of shortcut, or direct condition/action generators are needed.

ex) CreateUnit(1, "Boss #1", "test", "Player 1")

( CreateUnit may be single lua function )

Post has been edited 1 time(s), last time on Aug 12 2014, 9:19 am by trgk.



EUD

Aug 12 2014, 9:21 am CecilSunkure Post #14



Yeah I agree, shorthand functions would be super nice! Thank you for bringing this up so fast.

In order to make good shorthand functions I would have to know which functions to write. I'm not sure which shortcut functions for one-time triggers would actually be useful and worth my time to make. I decided for now to support *only* long-hand semantics becase anyone using LIT can make their own shorthand function like this:

Code
function SetResources( type, count, player )
    local res = Resources( )
    res:SetType( type )
    res:SetCount( count )
    res:SetPlayer( player )

    res:SetTo( )
end

-- Can be used like this (to create an action)
SetResources( "ore and gas", 100, Player4 )


It would be very nice to include these kinds of shortcut functions in LIT, but I just don't know which ones to make. After people use LIT a little bit and share their experiences (like you did last post so quickly!), I can write in some shorthand functions that are useful.

It will take some time and trial-error to figure out which semantics are the nicest.



None.

Aug 15 2014, 3:06 am CecilSunkure Post #15



Started adding in shorthand functions. For now there's only a few, so I've updated LIT with them. The download link in the OP is updated. LIT is now version 1.01.

I also created a demonstration map, download here. It's an implementation of xYoshix style screen-sized rooms with burrowed units. To create the triggers yourself you can just drag and drop ALTTP.lua onto LIT.exe, assuming everything is in the same folder. Alternatively, like the OP says, you can use a proper command line and tell LIT which folder ALTTP.lua resides in.

RoomLogic.lua is the most interesting part, and makes use of the string concatenation operator "..". The .. operator just pastes the strings on the left and right of itself together. Example:

variable = "This is a se" .. "ntence."

The variable will hold the value of "This is a sentence". The nice thing about concatenation is that you can make triggers for multiple players in a loop with this, as shown in RoomLogic.lua.

Some of the new shorthand functions are used in RoomLogic.lua as well.



None.

Aug 15 2014, 7:09 am Sacrieur Post #16

Still Napping

The download link can't be found :/



None.

Aug 15 2014, 4:18 pm CecilSunkure Post #17



Whoops, fixed it now. Thanks.



None.

Dec 18 2014, 7:39 am Sand Wraith Post #18

she/her

I find it really odd that generating
Code
Trigger("All players"){
is literally impossible. PlayerGroup(0) should produce such a thing. Similarly, it's impossible to generate Forces. (Is this because of considerations of mechanisms in StarCraft's handling of players in triggers or?...)

I got it to work after some trial and error. Feels pretty good.




Oct 28 2015, 9:57 pm CecilSunkure Post #19



Hey there, I didn't bother with All Players of Forces because you can just assign any player group yourself. For example, if players 2-4 were in Force 1, you can just make a player group for players 2-4, instead of in forces.

It's just me being a lazy programmer, plus when I make maps I personally never use all-players or forces. Just a preference.

Minor update:
Continued work late into last night, I actually regret how I wrote most of LIT and can see better ways of doing it after the year has passed. Oh well! It looks like there will be two major APIs, the "object oriented" way where you make an object and assign state to it, and short-hand functions that just print out trigger text, but don't store state.

My experience shows the shorthand functions are way nicer in almost every way, so as I go on using LIT over time I'll just write more and more short printing functions whenever a need for one comes up.

Some example code I wrote late last night:

link to code for using bomb from inventory



None.

Oct 31 2015, 2:12 am CecilSunkure Post #20



Here's a good example of why using a trigger generator rocks (any trigger generator!); say we are making some rooms and want to connect them together with two locations. Each location is placed at an entrance/exit of both rooms. Lets name the locations A and B. Lets assume the player has just one hero unit.

When a hero walks onto A we want to move the hero to B. When the hero walks onto B we want to move the hero to A. If either of these triggers occurred we want to keep it from happening again until the hero is not at location A or B (this prevents the hero from jumping from A to B infinitely).

This kind of doorway is very tedious to construct by-hand and takes time. Each doorway needs to be tested to make sure the triggers have no bugs. Instead we can write a function in Lua that LIT turns into triggers. We can test this function once and re-use every time we have a new pair of locations to act as a doorway.

Here's some Lua code I wrote for LIT:

Code
-- create the deathcounter variable with LIT
local roomDC = Deaths( )
roomDC:SetUnit( "Terran Physics Lab" )
roomDC:SetPlayer( 8 )

-- function that generates triggers to connect two locations
-- together to act as a doorway for a "hero unit" called LINK
function ConnectRooms( a, b )
    -- move from a to b
    p8:Conditions( )
    roomDC:SetCount( 0 )
    roomDC:Exactly( )
    BringExactly( 1, LINK, a, 1 )
    p8:Actions( )
    roomDC:SetCount( 1 )
    roomDC:SetTo( )
    MoveUnit( 1, LINK, 1, a, b )
    Preserve( )
   
    -- move from b to a
    p8:Conditions( )
    roomDC:SetCount( 0 )
    roomDC:Exactly( )
    BringExactly( 1, LINK, b, 1 )
    p8:Actions( )
    roomDC:SetCount( 1 )
    roomDC:SetTo( )
    MoveUnit( 1, LINK, 1, b, a )
    Preserve( )
   
    -- turn off the DC when not present at a or b
    p8:Conditions( )
    BringExactly( 1, LINK, a, 0 )
    BringExactly( 1, LINK, b, 0 )
    roomDC:SetCount( 1 )
    roomDC:Exactly( )
    p8:Actions( )
    roomDC:SetCount( 1 )
    roomDC:SetTo( )
    Preserve( )
end

ConnectRooms( "link's house a", "link's house b" )


Now each time I need to connect two locations together I use this line:

Code
ConnectRooms( "link's house a", "link's house b" )


If I would like to connect many different rooms together, we can do something like this:

Code
ConnectRooms( "link's house a", "link's house b" )
ConnectRooms( "castle front door a", "castle front door b" )
ConnectRooms( "cave a", "cave b" )
ConnectRooms( "triforce door a", "triforce door b" )


Proof:





None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[04:47 pm]
Dem0n -- then again w/e
[04:46 pm]
Dem0n -- It's hardly even a SEN server honestly. Just mostly the same 10 people saying dumb shit LMAO
[04:46 pm]
Dem0n -- NudeRaider
NudeRaider shouted: Voyager7456 there should probably be a place more obvious that gives the link to the discord server. I'd say we're past trial stage by now.
no tbh. Lots of dumb people that shouldn't be on it.
[04:45 pm]
Suicidal Insanity -- Naw, somebody just redefined what one standard moose is
[04:39 pm]
Dem0n -- Our Moosey's all grown up C|:'^ )
[04:36 pm]
Dem0n -- O__________________________________________________________O
[04:17 pm]
jjf28 -- moose is no longer a mini O.O
[10:41 am]
NudeRaider -- NudeRaider
NudeRaider shouted: Voyager7456 there should probably be a place more obvious that gives the link to the discord server. I'd say we're past trial stage by now.
In the menu. Probably an item under Site, or preferably next to Wiki
[10:40 am]
NudeRaider -- Voyager7456
Voyager7456 shouted: You download Discord and join the SEN server :P
there should probably be a place more obvious that gives the link to the discord server. I'd say we're past trial stage by now.
[08:53 pm]
O)FaRTy1billion[MM] -- I'm pretty sure you can use the web one on phone too
Please log in to shout.


Members Online: Roy, Smithjaq2, UEDCommander, jun3hong