Updating the wiki mission scripting tutorial

zonkmachine
Posts: 38
Joined: Mon Sep 20, 2021 3:18 pm

Updating the wiki mission scripting tutorial

Post by zonkmachine »

Hi!

I've had a go at refurbishing the mission scripting tutorial in the wiki pages a bit. I'm only getting started coding in lua myself but I'd reckon it's all within reach if I give it a month or so. First part updated is: Interacting with the game: Event-based programming, where I've just tweaked it to be correct, no big changes.

I'm now looking into: Interacting with the player: BBS forms, which is a long chapter and a bit heavy on information. I think it could be improved by splitting it into two parts. First part is on strings and internationalization and would consist of paragraphs 1 and 6, Internationalization and Mission flavours. I'll also add a part on string variables, {name}, {price}, etc. First draft almost ready.
zonkmachine
Posts: 38
Joined: Mon Sep 20, 2021 3:18 pm

Re: Updating the wiki mission scripting tutorial

Post by zonkmachine »

Q - What am I missing here? I'm trying to make a simple hello program work. It works something like four times out of five.

data/modules/hello.lua

Code: Select all

local Event = require 'Event'
local Comms = require 'Comms'

local onGameStart = function ()
  Comms.Message ('Welcome to Pioneer!')
end

Event.Register("onGameStart", onGameStart)
sturnclaw
Posts: 82
Joined: Tue Sep 18, 2018 12:20 am

Re: Updating the wiki mission scripting tutorial

Post by sturnclaw »

zonkmachine: there is no fixed order in which event callbacks are executed, meaning that the onGameStart callback that clears the comms log cache as part of a new game can run after the callback in which you've logged the start message. I'd recommend creating a Timer with a half-second delay that is responsible for actually logging the message.
impaktor
Posts: 1009
Joined: Fri Dec 20, 2013 9:54 am
Location: Tellus
Contact:

Re: Updating the wiki mission scripting tutorial

Post by impaktor »

@zonkmachine Huge thumbs up for updating the lua scripting on the wiki. It's been on the back of my mind to do for years. I think it was outdated already when I joined in 2013. I think your plan for the wiki sounds good, feel free to take "ownership" of that section of the wiki.

My only recent contribution was a page for a simple "hello world" script for making imgui-windows, based on code from sturnclaw, which you also can feel free to clarify/edit, (it could also be adopted to putting "hello world" tab to the debug window, or other screens in the game).

By the way, due to my many-year-old-plan to update the lua scripting page, I took some notes on bugs I had when I started with lua (my background then was C++), so feel free to incorporate the below to the wiki, in some form, if you find it valuable:

Code: Select all

if false == 0 then
    -- this will never be evaluated, since a bool is never a number
    print("1. never be here")
elseif true == 1 then
    -- this will never be evaluated
    print("2. never be here")
elseif 0 then
    -- all numbers are true, including 0!
    print("always here")
else
    error("we will never come here")
end
-- Only "nil" and "false" are evaluated as false.
zonkmachine
Posts: 38
Joined: Mon Sep 20, 2021 3:18 pm

Re: Updating the wiki mission scripting tutorial

Post by zonkmachine »

Thanks for the feedback!

@sturnclaw Thanks! I also got the tip on irc to use onShipDocked by @joonicks. I'll try and use both methods.

@impaktor Yep. Some of the concepts of Lua takes some getting used to. That code brings up the ones that got me the first time I looked into Lua. I'll try and fit it in somewhere. :)

I've created separate a new page, Strings and translation, and removed the corresponding part from Interacting with the player: BBS forms. It still needs some tweaks but in large I'm happy with it. All code snippets has been tested to work.
sturnclaw
Posts: 82
Joined: Tue Sep 18, 2018 12:20 am

Re: Updating the wiki mission scripting tutorial

Post by sturnclaw »

Thanks for the new wiki page zonkmachine! I've made a few minor edits and pointed the documentation to the Lua 5.2 manual (as that's the Lua version that Pioneer uses), but overall it's a very useful resource!
One point of clarification though - I've (sometime in the last year or so) fixed the issue where the game would crash if it can't find a language-specific translation file (and it also shouldn't crash if the requested translation resource doesn't exist at all); I'd appreciate it if you could confirm if that part of the wiki page is still valid, and if you still get a crash for whatever reason please report that on github.
zonkmachine
Posts: 38
Joined: Mon Sep 20, 2021 3:18 pm

Re: Updating the wiki mission scripting tutorial

Post by zonkmachine »

@sturnclaw Thanks for the improvements! I couldn't replicate the issue with Pioneer crashing on missing translations. I didn't write that note though. @impaktor did.
sturnclaw
Posts: 82
Joined: Tue Sep 18, 2018 12:20 am

Re: Updating the wiki mission scripting tutorial

Post by sturnclaw »

Probably an old left-over note from before the improvement was merged; I'm also unable to reproduce the crashes so feel free to remove that section :D
impaktor
Posts: 1009
Joined: Fri Dec 20, 2013 9:54 am
Location: Tellus
Contact:

Re: Updating the wiki mission scripting tutorial

Post by impaktor »

Yeah, I wrote that a few days ago, before the PR went up. I should remove the part about crashing.
zonkmachine
Posts: 38
Joined: Mon Sep 20, 2021 3:18 pm

Re: Updating the wiki mission scripting tutorial

Post by zonkmachine »

impaktor wrote: Mon Oct 11, 2021 4:37 pm Yeah, I wrote that a few days ago, before the PR went up. I should remove the part about crashing.
I reverted that change.

Q - When in the upstart process does the 'game clock' start ticking?
Post Reply