FAQ: Scripting Hints and Tips

Information related to the script editor and lua mechanics etc. Some useful mini scripts and other tips.

Q) Is there any way to get the object ID on mouse over?

Yes there sure is, try this in an object script or scene script:

function onUpdate(timeDelta)
   x,y,z = sky.raycastToCursor();
   hitID = entity.getLastHitEntityID();
   sprint("> "..hitID)
end

Q) Delete an object when clicked on

To delete an object when its clicked on requires two things to happen. One is to enable the mouse click events by calling this command once (This can be in a scene script.):

game.enableMouseRay(1); 

The second is on the object its self in a micro or external script:

obj = 0;
function onInit(objID)
   obj = objID;
end

function onClick( hitID  )
   entity.delete( obj );
end

Q)How to Communicate between Scripts

The are many times when developing complex systems and classes there is the need to send and receive data between different objects. This could be done by using global variables but would never be practical on a large project where there cold be 1000,s of dynamically controlled objects. It is far better to have the scripts send and receive data between each other, this way each object can manage its own data.

Examples of communicating between scripts on other objects can be found here: Communicating with Scripts

Q) How to Communicate with Modules

Not all dynamic controllers are created by script. In some situations it is easier and better for performance to use the module system. Skyline will happily run an object containing both a script, either external or micro script and a visual module graph. Tools have been provided for inter system communication between scripts and modules, lets take a look.

Examples of communicating between scripts and Modules can be found here: Communicating with Modules

Q) How to Communicate with Actions

Actions add a lot of performance friendly game mechanic functionality and are at the core of constructing cool game objects from entities. Actions themselves have their own Lua library “action.command()“ for getting and setting property values and specific actions have direct lua Event calls such as the “function doDamage(..)“

More information can be found here: Communicating with Actions

Bullets and spaceships

Physics for space ships, bullets etc, this is generally done using kinematic bodies that do not respond to forces such as gravity, with these you have to program the forces yourself. This is a far more efficient route rather than tring to manipulate individual objects gravity and used by many top games as you have full control over the body and is better for performance as its not calculated in the main physics world, yet still can interact.

Q) How do I access the weapons editor by script?

The weapons editor has its own library found here: Weapon Class

-- Examples
vol      = weapon.getEmptyClipVolume("scar");
animName = weapon.getAnim("scar", "shoot");
power    = weapon.getPower("scar");
clips    = weapon.getMaxClips("scar");
rounds   = weapon.getMaxRounds("scar");
damage   = weapon.getDamage("scar");
--etc

Q)

TEXT