Platinutonium wrote:-Make switches that remove or add objects?
I'm new to all of this, but here's the quick and dirty. The new levelgen stuff works through the "levelgen:subscribe()" mechanism. This function takes a member the following enum as its argument:
- Code:
Event.ShipSpawned
Event.ShipKilled
Event.PlayerJoined
Event.PlayerLeft
Event.MsgReceived
Event.NexusOpened
Event.NexusClosed
Event.ShipEnteredZone
Event.ShipLeftZone
The argument describes what "event" you want to listen for. There are no switches in Bitfighter, so the solution is to use zones, and have your switching action in the ShipEnteredZone event. So here's an example
- Code:
function main()
levelgen:subscribe(Event.ShipEnteredZone)
end
function onShipEnteredZone (ship, zone)
logprint("Ship " .. ship:getId() .. " entered zone " .. zone:getId())
-- do some stuff
end
The fist important part of this is the function main, where you put the code to be executed when the level is first loaded. Next, by calling levelgen:subscribe(Event.ShipEnteredZone) you're telling Bitfighter that you want to do something when any ship enters any zone. Bitfighter then looks for a function with a specific name of the form "on<Event Name>". In this case, onShipEnteredZone. The name of the function is determined by the event, and must match perfectly. When Bitfighter sees that a ship has entered a zone, it will call your onShipEnteredZone function.
Now, notice that onShipEnteredZone takes two arguments (which Bitfighter passes to it when it's called). These arguments are different for each function, (see
http://bitfighter.org/wiki/index.php/Pr ... ned_events [somewhat outdated]). In this case, the arguments are lua instances of the ship and zone involved in the event. This way you can test which zone or ship is involved in the event.
If you want to use it as a switch, you'll need a global variable (to keep track of whether your "switch" is on or off). Remember that global variables must be defined in the main function:
- Code:
function main()
levelgen:subscribe(Event.ShipEnteredZone)
-- set our global variable's starting value
isOn = false
end
function onShipEnteredZone (ship, zone)
if isOn then
logprint("On")
else
logprint("Off")
end
-- this will set isOn to true if it is false, and to false if it is true
isOn = not isOn
end
To add an item, use
- Code:
levelgen:addItem(ResourceItem.new(), 0, 0)
and replace ResourceItem with the name of the type of item you want to spawn
(I don't know about removing items, or spawning hostile bots)
To do something after a set amount of time:
- Code:
function main()
Timer:scheduleOnce(doThisLater, 2000)
end
function doThisLater()
levelgen:addItem(ResourceItem.new(), 0, 0)
end
scheduleOnce takes a function (or some other stuff, but it's complicated) and a delay as its argument. The function can be named pretty much anything you want, since you tell it which function to call. The delay is in milliseconds, so 2000 means 2 seconds.