"Interactiv" Tutorial for Lua

Hello all.

Have you ever thought “CDDA is such an awesome game with so much stuff”? I have a lot. There are so many items and buildings and monster and…
I want to contribute a little to the game. It’s easy with json modding, but I got into the possibilitys of lua. There is a very long list of CDDA-commands which allows to write scripts. I am not a programmer but lua seems to be easy. We could do a lot with it. I don’t understand why there is so few content written in lua. Let’s change this.

For me as a non-programmer it is still difficult to get acces to c++ calls and returns. So I thought we could to a little tutorial here. Or some kind of the “Tips, Tricks, and Newb Questions!” thread for lua. It would be nice if the people who are familiar with lua in CDDA share theire knowledge. We could gather Code Snippets, links to older threads with lua content in it and help each other programming. I offer to gather the stuff and extend the Wiki with it.

I have several differing opinions about this, but its be nice.

Please share them with me. For shure you have more informations then me. I’m only playing for a couple of weeks now.
If Lua is some sinking ship I don’t need to do this. Then I would rather concentrate on c++ instead.

LUA is hard. C++ is hard.

These are complex enough that there are university level courses to cover them. Youre asking for people to write a guide for free on a complex subject they themselves sometimes space over. There’s a reason its a full time ‘team’ job.

That said, the aim of this forum is to host and discuss an open game that was crowdfunded.
That said a guide is above and beyond.

And then who corrects/moniters the mistakes? Dont get me wrong, I too wish to learn more coding. I do some studying on my own time. But Im not going to pretend that even with a guide I could make my own code without error or asking for help.

And then, after all that, there is no ‘right way’ to write coding. There is a more efficient way and several ‘less’ efficient ways, but its all gets subjective at some point.

I agree with you in every point. Really.
Perhaps it wasn’t perfectly clear whats my intention. Perhaps I didn’t know this at all. :slight_smile:
Well I don’t expect someone who writes a 100 pages tutorial book for me or someone who is interested in giving a little input to the game. And this is not the place for learning the basics of a programming language. But there are pointers and calls written, waiting for some lua script to execute them. It seems there was once the idea to make it possible to write non-hardcoded scripts. Only very few took the advantage and uses this possibilities. Especially those ones who haven’t enough skill and time to learn and write code in C++ to copile and merge it to the sourcecode could benefit from a better documentation of using CDDA-Lua. My opinion: It is a great possibilitie to add interesting new stuff to the game.
Maybe 95% of the code written in the mods are json.This is great to add more guns, books, food … But if I wish to add a toothbrush I can’t add a new action which lets me clean my teeth (I am aware of that
ridiculous example :). Now json is not enough.

This is a point where I am in my attempt to write a mod. All in all I found only a few items written in lua, so I need help. I could try C++ instead and maybe it would be a shorter way becouse there are many actions done written to adapt and copy. But I don’t know, the Lua gets me.
So if I’m asking a question about my problems and someone helps me out, there will be content which is usefull for other modders. And to store some example-code in the wiki isn’t such a bad idea, isn’t it?
Of course, if there is no interest for it, it will be fine for me. Let’s say it’s an experiment.

[hr]

Enough bla bla. To the point. I need help
I have a iuse action from an item. After activate the item there should be a menu for some other actions.
It is possible ultra simple, but I didn’t know how the code for such a menu looks like.
Wiki says: create_uimenu() for creation of the menu and addentry(string) for entries.
What is the syntax for it? I have only this :frowning:

function iuse_analog_camera(item, active)

menu = game.create_uimenu()

end

game.register_iuse("IUSE_ANALOG_CAMERA", iuse_analog_camera)

Pisskop, can you advise me on some “LUA for beginner” book or online course? I am going to have a lot of free time in the immediate future.

I cant, because I don’t have one myself.

http://www.lua.org/start.html This is the basic giblets on their site.

Id start there too

https://www.lua.org/pil/contents.html

Im thinking my way into learning it, tbh. Im reading the code, stating exactly what it does, and trying to make my own.