Where best to search for "HowTo" (for client Lua scripting)?

Various topics about the game, the website, or anything else Freeciv related that doesn't fit elsewhere.
User avatar
Posts: 473
Joined: Wed Jan 30, 2013 12:15 am

Re: Where best to search for "HowTo"?

Postby JTN » Fri Aug 01, 2014 11:38 pm

ILoveLilyAllen wrote:I am currently running a game using "This is Freeciv version 2.5.0-beta1 (beta version), gui-gtk-2.0 client." I select the menu "Edit" and the item "Client Lua Script". This launches a new window which says "This is the Client Lua Console.". In that window I cannot type anything!

You should find that there's a single-line edit box below the Lua script output window, into which you can type stuff like your log.normal("Hello world")? Works for me in 2.5.0-beta1, anyway.

Posts: 29
Joined: Wed Jul 30, 2014 5:50 pm

Re: Where best to search for "HowTo" (for client Lua scripti

Postby ILoveLilyAllen » Sat Aug 02, 2014 5:22 am

Ah, thank you once again. I didn't notice that line!

Now I understand what you meant about typing in 'find_next_trade_route()'. Obviously the lua function code would need to be written anyway and presumably placed in one of the game files, but it seems that a much better/quicker/easier way (at least at the moment) is to use an external text editor to create and edit the lua script. Pressing 'Load Lua Script' and locating a file find_next_trade_route.lua would, for me anyway, be much preferable to typing in the function name in that edit line (and inevitably misspelling!).

Of course I intend to test this, but at first I am assuming that when you load a file it parses through to find the first executable code which isn't a function and runs from that point (if my memory serves me correctly from using lua in the dim distant past). I am also assuming that a function defined in the file you are running will be executed even if there is an identically named object elsewhere (known as local scope override or something!). If those assumptions hold, it may be better to have a "library" file with all the additional (or overridden) lua functions and just have the line(s) at the bottom with the specific code to run, which could be find_next_trade_route() - just hoping that the "hour glass" doesn't live up to it's name!

I did wonder how I might write that trade route utility. In-game I tend to choose the farthest city from the caravan/freight owner which doesn't already have the maximum number (on another continent if possible), but that's probably not always the "best" route.

Anyway apologies for waffling away for hours.