Various LUA Script Examples [indexed]

  • #1, by afrlmeTuesday, 06. November 2012, 21:48 12 years ago
    I will be indexing the various LUA script examples I add to my pastebin account BigStans got me to create. I will link to the script page & the reference page I used for the syntax!

    I believe amending them to a single thread is a better way to go than creating a new thread everytime & having to spend ages searching for each of them!

    [ABC]

    º Actions: startAction() | stopAction()

    control which & what type of actions to start|stop using variables within functions! script: here | project: here (4.2mb approx) ref: here & here status: working!

    º Animations: startAnimation() | stopAnimation()

    control which & what type of animations to start|stop using variables within functions! script: here | project: here (4.5mb approx) ref: here, here & here status: working!

    º createScreenshot()

    save a screenshot to a folder (includes incrementing count variable to auto amend a screenshot number to the png file like so: screenshot_1.png) script: here | script *new*: here project: here (2.3mb approx) ref: here status: working!

    *** update: now checks for existing files at game launch & adds total +1 to the count variable which prevents overwriting of files!

    *** update 2: ignore previous update!

    I removed check for existing files + count on game launch as it doesn't take into account that people may have deleted some of the screenshots + thus it stops counting as soon as it returns a file does not exist! - I've left the first update script link on here for you to check out mind.

    the *new* script creates a loop which checks if a file exists + keeps on adding +1 to the count variable until a file doesn't exist else it saves screen_x.png + adds +1 to the count variable!

    º Config.ini [read | delete]

    gets various info from config.ini so we can declare conditions & values or deletes config.ini so a new version can be saved. script: here | project: n/a ref: n/a status: working!

    *** update: now working perfectly!

    º Config.ini [write]

    creates a temporary file of changed settings & is renamed once config.ini has been deleted. script: here | project: n/a ref: n/a status: working!

    *** update: now working perfectly!

    [DEF]

    [GHI]

    [JKL]

    [MNO]

    [PQR]

    º Print()

    print message to log (messages.txt) [various methods] script: here | project: n/a ref: n/a status: working!

    [STU]

    º startDefaultBrowser()

    launch an url in your default web browser from within V.S player (app | .exe) script: here | project: n/a ref: here status: working!

    [VWX]

    º Volume: getVolume() | setVolume()

    get|set current volume level for declared int {0 = music, 1 = sound, 2 = speech} also plays a sound or speech file from a sceneAction depending on current int declared. script: here | project: n/a ref: getVolume & setVolume & startAction & einzelkaempfer's slider script status: working!

    º Volume: Modified Slider Script

    my modified english version of einzelkaempfer's volume slider script with extra bonus tweaks & fixes: see "notes" in the script for details! script: here | project: here (18.7mb approx) step by step: here ref: getVolume & setVolume & startAction & StartAnimation & einzelkaempfer's slider script status: working!

    [YZ]

    [END]

    quick random note: I've been told Daedalic script their own functions into V.S editor so if you are a wizard with LUA (unlike me) then if you check out: Program Files > Visionaire3 > lua. you'll find 3 files that you could potentially write your own functions/actions & so on into!

    you would have to make some edits to the files found in the xml folder also!

    Imperator

    7278 Posts


  • #2, by afrlmeWednesday, 07. November 2012, 03:05 12 years ago
    Just created a Volume Control script that plays a sound / speech file using various if else statements & a few object\scene actions.

    It checks if volume = 100% or more & if not it adds +10% volume to declared int value. it checks if volume = 0% or less & subtracts -10% volume from declared int value.

    add\subtract actions are declared in an execute script with PlusMinus_Vol(int, false|true) true = add | false = subtract

    int = {0 = music, 1 = sound, 2 = speech}

    Check einzelkaempfer's Volume Slider Script - which is in German - for more ideas.

    I will be uploading my modified English version of his script when I've finished working on my mock menu template which includes:

    º new game º resume game º advanced save/load/delete menu (various values & conditions to control) º options menu (change vol, fullscreen, resolution, subtitles, language etc) º bonus content menu (content unlocked via achievements|score system - no sure yet) º quit game

    extras included: º launch default browser º create multiple screenshots º read | write | delete config.ini (when I've finished the script)

    & so on.

    P.S if anyone knows a better way of playing sound or speech files within V.S with Lua rather than having to create/use an action then please let me know as I tried various methods I found on google & didn't have much luck other than returning a NIL value in the log file!

    Cheers, Lee smile

    Imperator

    7278 Posts

  • #3, by afrlmeWednesday, 07. November 2012, 18:00 12 years ago
    I've started on a multiple startAction() | stopAction() script which is currently working to a point!

    as the code currently is, it will start the action assigned via execute function but it does not print my true/false messages to the log; instead we get an error message!

    attempt to concatenate local 'act' (a userdata value)

    if I change "action_1" to local action_1 then it doesn't perform the assigned action & gives us an error about not using the correct/expected syntax!

    Invalid syntax for command startAction Invalid syntax for command stopAction

    current script below:

    
    -- some quick examples of startAction() | stopAction()
    -- start action has a return value so we'll do a version for that too!
    -- execute startAction in an object action like so: start_action_num(local variable name)
    -- execute stopAction in an object action like so: stop_action_num(local variable name)

    -- globals (declare the action & path into a local variable) -- local action_1 = getObject('Scenes[scene_name].SceneActions[action_name]') -- scene action tab -- local action_2 = getObject('Scenes[scene_name].SceneObjects[object_name].ObjectActions[action_name]') -- object action tab -- local action_3 = getObject('Characters[character_name].CharacterActions[action_name]') -- character action tab action_1 = getObject('Scenes[Options_Menu].SceneActions[play_sound]')

    function start_action_num(act) if startAction(act) then print('action ' .. act .. ' has been started!') else print('action ' .. act .. ' could not be started!') end end

    function stop_action_num(act) stopAction(act) print('action ' .. act .. ' has been stopped!') end

    anyone have any idea what's wrong with the script?

    much appreciated, cheers smile

    Imperator

    7278 Posts

  • #4, by beyondthestarsFriday, 09. November 2012, 00:27 12 years ago
    This is really cool! Thanks for doing this smile

    Newbie

    0 Posts

  • #5, by afrlmeFriday, 09. November 2012, 01:09 12 years ago
    no problem man smile

    Imperator

    7278 Posts

  • #6, by afrlmeFriday, 09. November 2012, 18:21 12 years ago
    So, I've not tested this yet but it should work!

    essentially I've created an LUA script which allows us to define which action we want to start via the "typ" variable added to the function!

    if we set typ as 1 then it takes info added into the csname & act variables only! [SceneAction] if we set typ as 2 then it takes info added into the csname, objname & act variables! [scene, ObjAction] if we set typ as 3 then it takes info added into the csname & act variables only! [CharacterAction]

    I don't think it will work properly if you don't add any text into the objname tab if not required so just add nil or whatever.

    I suppose I could make this simpler by having a different function for each type of getObject as opposed to relying on if else statements but it does mean we would have to create unique code for each function.

    
    -- * notes * --
    -- some quick examples of startAction() | stopAction()
    -- start action has a return value so we'll do a version for that too!
    -- execute startAction in an object action like so: start_action(typ, csname, objname, act)
    -- execute stopAction in an object action like so: stop_action(typ, csname, objname, act)

    -- * function variables * -- -- typ = int{1,2 or 3} - (1(sceneAction), 2(scene,objectAction), 3(characterAction)) -- csname = string (nil or character|scene name) -- objname = string (nil or scene object name) -- act = string (action name)

    -- * example * -- -- startAction(3, Robert, nil, play_sound) -- starts "play_sound" found via character Robert's action tab!

    function start_action(typ, csname, objname, act) -- local variables! local act1 = getObject('Scenes[' .. csname .. '].SceneActions[' .. act .. ']') local act2 = getObject('Scenes[' .. csname .. '].SceneObjects[' .. objname .. '].SceneActions[' .. act .. ']') local act3 = getObject('Characters[' .. csname .. '].CharacterActions[' .. act .. ']') if typ == 1 then if startAction(act1) then print('SceneAction ' .. csname .. ', ' .. act .. ' has been started!') end else if typ == 2 then if startAction(act2) then print('SceneAction ' .. csname .. ', ' .. objname .. ', ' .. act .. ' has been started!') end else if typ == 3 then if startAction(act3) then print('CharacterAction ' .. csname .. ', ' .. act .. ' has been started!') end end -- typ = 3 end -- typ = 2 end -- typ = 1

    function stop_action(typ, csname, objname, act) local act1 = getObject('Scenes[' .. csname .. '].SceneActions[' .. act .. ']') local act2 = getObject('Scenes[' .. csname .. '].SceneObjects[' .. objname .. '].SceneActions[' .. act .. ']') local act3 = getObject('Characters[' .. csname .. '].CharacterActions[' .. act .. ']') if typ == 1 then stopAction(act1) print('SceneAction ' .. csname .. ', ' .. act .. ' has been stopped!') else if typ == 2 then stopAction(act2) print('SceneAction ' .. csname .. ', ' .. objname .. ', ' .. act .. ' has been stopped!') else if typ == 3 then stopAction(act3) print('CharacterAction ' .. csname .. ', ' .. act .. ' has been stopped!') end -- typ = 3 end -- typ = 2 end -- typ = 1

    Imperator

    7278 Posts

  • #7, by afrlmeFriday, 09. November 2012, 19:52 12 years ago
    bawsack razz

    I know what's wrong with my code - I will upload the amended version later after I've cooked dinner wink

    I forgot to make them strings & we need to separate the local variables too or else they throw errors at us but never fear as I ken what to do now!

    Safe smile

    Imperator

    7278 Posts

  • #8, by afrlmeFriday, 09. November 2012, 23:15 12 years ago
    ok variable startAction(), stopAction() script is now working! added it to the index along with a quick project file for it !!!

    P.S no idea what's going on with the formatting of the content inside the Spoiler tags ... will see if Calli can sort it out wink

    Imperator

    7278 Posts

  • #9, by afrlmeSunday, 11. November 2012, 04:58 12 years ago
    just added a modified English version of einzelkaempfer's volume slider script!

    I've added various tweaks & fixes to it ... º active handle image on mouse button hold * º play sound/speech file when mouse button released depending on current vol type º play sound/speech file after clicking plus/minus buttons depending on current vol type º added a simple fix to prevent the sliders randomly moving ** º added some print statements - feel free to -- comment them out!

    * this was a right twatters'n'maddison to add as it didn't like my if else statement to define which animation to re-position & it also didn't like swapping animations within the same object - both gave me many errors so I worked around by adding secondary slider objects with the required animation frames. also I had to include a separate setVolConPos for the plus/minus buttons otherwise we got errors about missing objects due to the active handle animations being inactive.

    ** sometimes the sliders seemed to stick & would continue to move with the mouse even if you wasn' t in the slider area anymore or it didn't seem to register mouse button released.

    -- * --

    I will sort out a thread with screenshots to explain how it all works the morrow as it's late now - or early depending on how you view/regard time - & I'm a wee bit knackered!

    but for now you can check out the project file I included in the spoiler smile

    Imperator

    7278 Posts

  • #10, by afrlmeTuesday, 13. November 2012, 18:57 12 years ago
    added variable function; start|stopAnimation to the index including an example project file smile

    Imperator

    7278 Posts

  • #11, by afrlmeThursday, 15. November 2012, 17:17 12 years ago
    edited createScreenshot() script ...

    I've added an if file exists checker to be executed on game start action which will start a loop which will count the files & add the number into a variable named count ...

    continues to loop until file doesn't exist & then prints current amount of saved screenshots & the next screenshot will be screen_(number).png

    much better than before as it would have overwritten any files starting from screen_0.png!

    check the first post index for the script wink

    Imperator

    7278 Posts