Getting & Setting values for variables via EXEC.lua

edited March 2016 in EmptyEpsilon
I see how to run some scripting from exec.lua from a web page, (http://bridgesim.net/discussion/comment/1196/#Comment_1196) but I'm not able to set & get variable values from there. I could use some examples on how to do this as apparently I can't figure this out.

Here's what I want to be able to do:
Read a value from a known variable/array
Set a value from a known variable/array

Quick Example:
Create a web interface for keeping track of inventory in a cargo hold.
inventory["stembolts"]=1 -- Number of stembolts in inventory

Create a web interface for Engineering for recalibrating reactor & engines
calibration["reactors"]=3 -- if greater than 0, multiply it with heat to decrease efficiency

Comments

  • Each run of the exec.lua runs in it's own "sandbox" so variables set there are "lost" after the script is done. This is done to prevent an exec.lua run messing up a scenario script or a different use of the API.

    However, you can set any custom variable on a player ship:
    player = getPlayerShip(-1)
    if player.inventory == nil then player.inventory = {} end
    player.inventory["stembolts"] = 1
  • Can a station like Relay get access to that value when it is set from exec.lua?
  • Not directly, but any other script (including comms scripts) can access these values as well.

    Example, this script sets some custom properties on a station:
    https://github.com/daid/EmptyEpsilon/blob/master/scripts/scenario_06_battlefield.lua#L12
    Which are used by the station comm script later on:
    https://github.com/daid/EmptyEpsilon/blob/master/scripts/comms_station.lua#L126

    (As for having an actually inventory to manage. I'm thinking about different ways to do that. I'll make a new post about it)
  • daid said:

    Not directly, but any other script (including comms scripts) can access these values as well.

    I figured I would have create scripts to handle the new info.
Sign In or Register to comment.