Best Build 21 Screenshot

Log in to vote!

Latest Posts

Topic: I'd like to make a scenario without knowing lua. is that realistic?

Joined: 2014-09-15, 18:35
Posts: 1642
One Elder of Players
Posted at: 2017-01-04, 18:18

I have an idea for a scenario in the dolomites map brewing in my head. It would require only few basic features:

  • making messages pop up when specific actions are taken (conquering of a certain spot, defeating a certain player, gaining sight of something).
  • including pictures in those messages; i intend the scenario to be also a sort of tour, and it would need real images
  • changing seasons: on a timer of something around one hour, the map should switch from summer to winter and viceversa, and the terrain should change by type: for example, summer mountain 1 would become winter mountain 1; mountain passes would become impassable snow, but they can certainly be set up with a mechanism similar to that used in the trident of fire scenario
  • some trigger for difficulty level, linked to building a certain building in a certain place, which would cause the AI to gain benefits for free.

Today I looked into it. Unfortunately, the wiki on scripting scenarios is ... less than useful

This section is intentionally cut short. There are excellent tutorials in Luas Wiki and there is a complete book free online: Programming in Lua. You should definitively start there to learn Lua.

really? I look for advice on how to make a scenario and I find "go to those links and learn lua"? It's like I ask how to fix my bike and I am told to go read a book on mechanics that will teach me how to make a car or a plane. I don't have the mix of time, intention and commitment needed to learn lua. I was hoping that I could get away with figuring out a few rudiments needed only for making a scenario. After all, I don't need to learn a whole programming language. I only need a handful of triggers; if this terrain comes under control of blue player, then make a window with a message appear. After that much time passes, change all instances of a certain terrain with a certain other terrain. it looks relatively easy. of course, I am well aware that everything you don't know how to do looks easier than it really is.

And so comes the point of my question. is it realistic that I can only learn how to work those handful of triggers to make a working scenario? or I don't really have a chance of managing it unless I become at least passably competent at lua? Does it makes sense for me to try without the commitment of becoming a programmer?

If the answer is "no, you have no chance of managing to make a scenario unless you become good with lua", then this bit of information should be addded to the wiki page. As it is, it sounds dismissive to the point of rudeness, at least to me.

Also, can someone recommend me a good lua editor usable under windows? I wanted to see if I can figure something out by looking at the scripting of existing scenarios and campaigns; at the moment I just use notepad to open lua files, but notepad does mess the formatting, and it makes really difficult to figure out what was going on. I've been using it so far to read stuff like the preferred growth parameters of trees or the working time of buildings, but no more

Top Quote
Joined: 2016-05-01, 14:52
Posts: 49
Pry about Widelands
Posted at: 2017-01-04, 19:14

I only had a brief look on the lua-section of the wiki myself. The part about "go and learn the lua-basics first" put me off a bit, too, at first. Though it's understandable that it would be quite some (unnecessary) work to write another guide for these basics. A few months ago I taught myself StarBasic to write a macro for LibreOffice, a project of similar size and complexity, I think. I'd say you don't have to worry too much. As far as I know, lua is a fairly easy language to learn. You will spend some time researching stuff in the books again and again but you don't have to get an expert to script this scenario. It's mostly about knowing how to declare and use variables and the syntax of operations, checks, loops and functions, I guess. The by far most tricky part would be the season changing, especially if you want to replace walkable with impassable terrain.

Putting a link to a specific lua-tutorial suitable for scenarios in the wiki would be quite helpful though.

Top Quote
Joined: 2013-02-18, 20:48
Posts: 1887
One Elder of Players
Location: Germany
Posted at: 2017-01-04, 20:01

Programming has always two parts:

  1. Some knowlegde of the programming language. But mostly all basics are even over all programming languages: Loops, Variables, If-statements, tables (arrays). They differ a bit by the syntax, but if you know about them, you could easily dive into Lua i believe.
  2. Knowledge of some APIs. In this case all the stuff of the widelands Lua scripting API. This means you have to learn when and how to use e.g. a map-object or a game-object. Also which functions all the objects provide and what they are good for.

From my point of view the second point is the most difficult task. But especially related to this point you could always ask here in the Forum for help face-smile.png

The existing campaigns and scenarios are a good point to start with. E.g. the atlantean campaign has code to change terrain. You could copy the code and adjust it to your needs.

As Editor i use komodo-edit. I use it mostly for programming python, but it has the same features for programming Lua i think:

  1. Code highlighting, e.g. all braces are colored blue, strings are red, numbers are orange, comments are green and so on
  2. Code completion, e.g. automatic closing braces
  3. Smart indenting of code
  4. Managing different projects
  5. Open recently used files (project) on startup

But i think each person has his own favorite editor face-wink.png

Top Quote
Joined: 2013-10-07, 15:56
Posts: 3205
One Elder of Players
Location: RenderedRect
Posted at: 2017-01-05, 17:35

My favourite editor is Geany - it's available for MacOS, Windows and Linux.

Your best bet to get going is to copy an existing scenario and stealing code from scenarios as you go along, then using our API documentation to look for any other functions that you need. I do a lot of "frankencoding" myself face-wink.png

You should be familiar with some basic programming concepts (variables, conditional statement: if... else, loops, arrays/tables, and functions).

Make sure to declare all your variables as local.

If you get stuck, create a branch so that we can look at the code and ask for help.

Also, if you need a function that isn't available in our API, ask and we'll look into creating one.

The scripting reference definitely needs more info - it's an ongoing project. I'm still busy documenting the tribes and worlds ATM.

Edited: 2017-01-05, 17:36

Busy indexing nil values

Top Quote