Capricorn 76
This Lua tutorial demonstrates how to create a background task using the ScriptENGINE. As you'll discover, you can use the ScriptENGINE to create just about any sort of application you like.


---------------------------
---------------------------
-- Tutorial: Background task. Test 1
-- Sleep for 10sec, then display a message to the user.
--
-- Copyright (c) 2006-2008 Capricorn 76 Pty. Ltd.
---------------------------
---------------------------


---------------------------
-- Run in the background for 10seconds
---------------------------
IApp:sleep(10000);

---------------------------
-- Initialise the sound engine, ask it to detect the sound driver
---------------------------
local soundInitialised = ISound:init(   'AUTO_DETECT_SOUND',    -- Instead of using hard-coded strings, we could IApp:load('constantsSoundDrivers.e76script') and use the pre-defined constants.
                            20,                 -- Frame rate for sound updating (how many times a sec the 3D position is updated when viewing a 3D scene)
                            0,                  -- Thread priority. The sound engine runs in a different thread to the graphics engine. This controls its thread priority level compared to other threads in the system.
                            true);              -- Silent errors are on, so ScriptENGINE will not raise an error. But this function will return 'false'.

---------------------------
-- Try to initialise sound, so we can play an alert sound
---------------------------
if (soundInitialised) then
    ---------------------------
    -- Load and play a sound
    ---------------------------
    local sndId = ISound:load('snd', 'tutorial.ogg');
    if (sndId) then
        ISound:play(sndId);
    end

    ---------------------------
    -- Show a message to the user
    ---------------------------
    IApp:showMessageBoxOk('Background task complete', 'Information');

    ---------------------------
    -- Close the engine, the window will close, and the program will terminate
    ---------------------------
    ISound:destroy();

else
    ---------------------------
    -- If we failed to open the sound device (the user may not have one installed), then just show a message to the user
    ---------------------------
    IApp:showMessageBoxOk('Background task complete', 'Information');

end


Copyright © 2006-23 Sep 2009 Capricorn 76 Pty. Ltd. (created on Wed Sep 23 16:49:11 2009)