Various LUA Script Examples [indexed]

  • #10, 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


  • #11, by afrlmeThursday, 15. November 2012, 21:38 12 years ago
    ok ladies & gentlemen ...

    I now have the config.ini script reading & writing! (finally)

    I will edit my pastebin scripts with the new version & will leave a message in here to let you know when I've finished smile

    I'm still adding if else statements & setValue:So So to it but so far I now have it reading all lines & setting conditions for subtitles & fullscreen + prints a message to let you know if it set as true or false or a string value in case of language & resolution!

    quick look at what it printed in my log file. I was testing it on the first 2 lines of which one is a file = data & the other being a #hashed out comment line! third & fourth lines display is/set to off/on depending on what's in the config.ini smile

    
    21:42:38: Skipped line 1: File = config_ini_v5.ved
    21:42:38: Skipped line 2: # Fullscreen = {Yes|No}
    21:42:38: fullscreen mode is on - read
    21:42:38: subtitles are currently set to on - read
    

    Imperator

    7278 Posts

  • #12, by KinecFriday, 16. November 2012, 01:26 12 years ago
    Thanks for your work, really appreciate it!

    Newbie

    15 Posts

  • #13, by afrlmeFriday, 16. November 2012, 03:28 12 years ago
    de naaaa smile

    & err 'ack!, fuck!, bugrit & baws!

    my config.ini example project file just got corrupted ... all objects, settings & scripts wiped (crashed while saving the project) - oh well roll

    too late to rebuild now - luckily I have (almost) latest version of my scripts on the pastebin - shall finish it the morrow wink

    Imperator

    7278 Posts

  • #14, by afrlmeSaturday, 17. November 2012, 03:13 12 years ago
    actually the corrupted file was a blessing in disguise of sorts seeing as it removed all the other clutter I'd been testing on the file!

    I'm only adding what's necessary to the new version!

    I should have a template file ready soon for the config.ini script, including the amended screenshot & modified volume slider scripts!

    I'm still in the process of having to re-add the objects & conditions that were corrupted.

    Imperator

    7278 Posts

  • #15, by afrlmeSunday, 18. November 2012, 02:14 12 years ago
    fixed a bug on the "Volume: Modified Slider Script" ... check the step by step link for details & I'm re-uploading the fixed project file now wink

    * oops apparently I added an 'l' on the end of .rarl like so - project file link fixed now - enjoy!

    Imperator

    7278 Posts

  • #16, by afrlmeThursday, 22. November 2012, 18:33 12 years ago
    anyone have any requests?

    I was going to try the hook function & maybe see if I could sort a displayed timer next ...

    I think the hook function allows precision positioning of displayed text (well that's what I gathered from the syntax page) which would be useful if you are planning on displaying text in a box with/without face avatars (animated or not)

    the timer on the other hand might be a bit complicated as I think we require LUA plugins to create one? but I'm sure there will be a work-around to create one without wink

    Imperator

    7278 Posts

  • #17, by GlenfxWednesday, 28. November 2012, 23:06 12 years ago
    I dont know why i didnt see this one before, but it's really cool!. grin

    Newbie

    72 Posts

  • #18, by afrlmeWednesday, 28. November 2012, 23:32 12 years ago
    unless you have "all languages" ticked then probably because each time I edit the thread it defaults back to German for some reason & I often forget to re-tick the English setting.

    Cheers wink

    Imperator

    7278 Posts

  • #19, by afrlmeFriday, 30. November 2012, 15:32 12 years ago
    I forgot to add a line of code to my screenshot script which prevents it from adding +1 to the count if screenshot amount = 0 ...

    technically I could have made it read/write the screenshot amount from/to the config.ini or any other file but I think using LUA was the better way to go seeing as my method counts the amount of screenshot files in the screenshot folder ... whereas the files can be deleted but the config.ini wouldn't know that!

    hmm then again my script also has a slight snag - if you deleted a single screenshot file say number 3 & there were 5 screenshot files then it would stop counting at screenshot 2 & overwrite any after that number.

    so I guess I could counter this easily by adding a checker to see if screenshot_x.png exists first.

    haha bugrit!

    I will see if I can sort this out later the day along with a project file & hopefully I'll try & finish my menu template for you all as well.

    safe smile

    Imperator

    7278 Posts

  • #20, by afrlmeFriday, 30. November 2012, 18:38 12 years ago
    ok dokie I scrapped the original createScreenshot() method for a much improved version which checks if a file already exists before saving as opposed to the previous script which counted the amount of screenshots that exist on game launch.

    the problem with the previous script was that it didn't take into account that if someone deleted a random screen_x.png file that it stopped looping the check_cond() function as soon as it returned a file does not exist!

    the new method runs when you hit the create screenshot key - "F12" in this case & continues to loop until it returns a file does not exist!

    this method prevents you from accidentally overwriting existing files & on the whole the amount of code needed is significantly much less than the first script wink

    I have left the original script link on the thread & have also added a project file for the new script version!

    P.S don't forget to comment out the 2 print statements on the file exists part - you'll know which they are as I added a "-- comment this out ..." after both of them, otherwise each time you press screenshot it will print a load of "screen_x.png already exists!" into the log file (messages.txt) - which I only added to check if the script was working correctly smile

    if you have noticed I have recently started adding extra "print('-- * --')" to my scripts before certain print statements ... I have been adding these to create a line break (separation line) between various log messages so we don't end up with a ton of clumped together randomness!

    Imperator

    7278 Posts