Jump to content

Recommended Posts

I started the Lua project today.

First i thought it would be a fair challenge in the end it was easy and i already managed to add a script today too.

Here is what i did so far:

This script

function start() 
	AddResearch("InteriorDecor")
end

Adds InteriorDecor:

 

Now the big wishlist is open what functions and triggers do you want to see?

luaresearch.jpg

Link to comment
Share on other sites

Sounds good, but I have one big question: why use lua?

What I mean is: we got the C# code in the DLL already. We make calls with harmony. Why should we add lua and how do we call lua scripts? So far I have only seen lua being used for modding in games where the DLL access is unavailable. If I understood why I should consider lua, then I would likely be way more likely to come up with proper functionality requirements.

39 minutes ago, Rainbowdesign said:

Well too bad no one answered

I wanted to mod ONI, but other stuff goes on around me today and I haven't got the time to mod or even keep up with the forum activity. This includes replying to a thread I didn't even read until right now.

Link to comment
Share on other sites

4 hours ago, Nightinggale said:

If I understood why I should consider lua, then I would likely be way more likely to come up with proper functionality requirements.

Since its pretty much ready only unfinished I will upload and link it in a few minutes, maybe you understand then.

There are some benefits: you can do something like adding a research with a single line, with the proper implementations everyone can easy do basic scripting. Easy means here: very little code and high accessible, no c#+harmony knowledge (believe me lua is MUCH easier to learn)

no compile and no extra dlls just text files.

text files can be very easy modified.

For implemented stuff you can do something with little effort you would otherwise need much more effort.

Well you will see i prepare it now.

 

4 hours ago, Nightinggale said:

I wanted to mod ONI, but other stuff goes on around me today and I haven't got the time to mod or even keep up with the forum activity. This includes replying to a thread I didn't even read until right now.

Actually it was more a "Why is no one seriously interested in modding oni and answers" which does explicitly excludes you, since you are seriously modding...

Actually i have seen a bunch of people starting i think i have seen 20 in the forum an chat who wrote "I want to mod i want to mod" Thinking about that maybe the problem is that for modding oni they need to be industry grade programmers certainly some abandoned the idea because of that.

Link to comment
Share on other sites

 

There it is. It works on my system so far i fixed all bugs i found already however dont expect everything to work 100% sure . You need to extract and drop it in the modfolder.

The actual useful functions are right now:

AddResearch

AddRecipe

GetTurnNumber

You could as example add a recipe on a turn or give the player a research on a turn.

LuaScriptingEngine.zip

Link to comment
Share on other sites

i appreciate this lua implementation if it works as intended.

Its much easier for many folks around to use lua, maybe the already know this language. The big question here is, is it effecting the games performance in any way to use another layer? I dont think this question can be answered with just a few lines, but anytime later with heavy modded games. 

Link to comment
Share on other sites

2 minutes ago, SharraShimada said:

The big question here is, is it effecting the games performance in any way to use another layer?

Actually it can lua has a backend layer of c# which would do any heavy lifting whats done in lua is intended only to do smaller calculations and starting instructions.

But in real terms of performance you are right lua is 100 times slower than c# (i actually tested it a while ago with a loop) but who cares if there are only 100 or so instructions?

Link to comment
Share on other sites

6 minutes ago, SharraShimada said:

And we all know, there are some people out there, who will throw every possible mod at the game they can find. 

No computing power in the world can compute an infinite loop like while(true).

If people do bad coding there is nothing the backend can do about that the only solution would be not to use that mod then or find them a teacher to improve planing and coding skills.

Like as example my seek mod does seek the whole map for elements but i coded it well and it really eats only few frames. (its in c# but you would expect this kind of tool eat the CPU alive)

Link to comment
Share on other sites

I can see potential in this, perhaps even without performance pitfalls. Say you expand this to allow adding new buildings. There will be code, which is called every 200 ms. This shouldn't be in lua for performance reasons, but what if the config is lua exposed? It executes once at startup and what if it can add components to the GameObject using lua. This way it can be execute once code in lua to add say an element converter, which then in C# converts x mass of element a to element b once a second. It seems doable.

My biggest concern in this regard is savegames. If you can add something to lua, which alters the savegames, won't it end up as a nightmare to avoid breaking savegames? It's not like it's always trivial even the way it is right now. I would very carefully consider if it would make sense to allow lua code access to something, which can render savegames unreadable. After all isn't the lua interface something, which is targeted at the less skilled programmers?

Link to comment
Share on other sites

One idea, which might be useful for novice modders would be some API to alter existing buildings. For instance people just requested a gas range with lower gas usage. It's trivial with a postfix, but it made me wonder if that would be a good domain for lua.

I'm not an expert in lua (I tried it and happily forgot all :p). However wouldn't it be possible to make some sort of get building function, which returns a lua class, which is a wrapper for a C# class? This class would then have references to the building in question. One function would then be a get component, which then returns a component wrapper.

I wonder if that is doable and how much can be modded using lua only if we go that way.

Link to comment
Share on other sites

9 hours ago, trevice said:

Nice job. Is there source code available? Just curiosity ;)

i uploaded them now to: https://github.com/rainbowdesign/OxygenNotIncluded-Mods/tree/master/sources/LuaScriptingEngine

5 hours ago, Nightinggale said:

There will be code, which is called every 200 ms.

I want to start it with different entry points.

This is also a bit frustrating since i dont know where to set the entry points with harmony.

Rightnow i have on Startup, onupdate and on mapgenerated. I am pretty sure however i did choose some bad points there.

5 hours ago, Nightinggale said:

This way it can be execute once code in lua to add say an element converter, which then in C# converts x mass of element a to element b once a second.

I have already an engine that can parse the map for elements and manipulate them i just need to integrate it with lua so this will certainly be possible soon.

 

5 hours ago, Nightinggale said:

After all isn't the lua interface something, which is targeted at the less skilled programmers?

Less skilled maybe, i just hope they will not write total trash. I do not really plan to expose every corner of the game but since other programmer could add functions they could expose.

However i think about a safe mode.

Beside that I exposed element and elementloader today and it was able to do this:


    stone=GetElement("SandStone")
    stone.highTemp=10.0

That certainly made the savegame less playable :D

28 minutes ago, Nightinggale said:

 

I wonder if that is doable and how much can be modded using lua only if we go that way.

I will try that i think its well doable.

Especially since i added class support already

Link to comment
Share on other sites

I'm really wondering what you are doing, because your quotes are nearly unreadable. Dark gray text on black background :shock:

Other people quote with black text on white background, kind of like the top of the screenshot. That's much more readable.

image.thumb.png.ab3ba8b0cc95483c0af2ce9a55a40ac0.png

Link to comment
Share on other sites

4 hours ago, Nightinggale said:

One idea, which might be useful for novice modders would be some API to alter existing buildings.

I looked into it and its not done with exposing the class since it only contains the functions.

Trevice did something like this maybe that can be adapted.

Also i have trouble to make it possible to register classes with lua i dont really find a way to get the class from a string.

Link to comment
Share on other sites

// Assets
public static BuildingDef GetBuildingDef(string prefab_id)
{
	return Assets.GetDef(Assets.BuildingDefs, prefab_id);
}

That should make it possible to turn a string into a BuildingDef. Next is gaining access to the following data in BuildingDef:


	public GameObject BuildingComplete;

	public GameObject BuildingPreview;

	public GameObject BuildingUnderConstruction;

I haven't tried accessing it this way, but I don't see why it shouldn't work.

Link to comment
Share on other sites

I guess it surely belongs to core.

So i did now:


        public static BuildingDef GetBuildingDef(string prefab_id)
        {
            return Assets.GetBuildingDef(prefab_id);
        }

but i dont understand how to expose:

 

public GameObject BuildingComplete;

public GameObject BuildingPreview;

public GameObject BuildingUnderConstruction;

 

I also want a way to register a type from a string, but all i get is t is a variable but is used like a type and i really dont find a solution for this:

        public static void RegisterType(string typename)
        {
            Type t = Type.GetType(typename);
            RegisterType<t>(typename);
            //somehow convert the typename to the type
        }
Link to comment
Share on other sites

Some clarifications seems to be needed here.

There is a static method called Assets.GetBuildingDef in the base game. It reads a string and provides the BuildingDef where prefabID (aka ID when creating) matches the argument. In other words you will get hold of the instance of the BuildingDef class for the building in question.

The BuildingDef class has those 3 GameObjects and to make everything easier, they are even public.

This means (if I get this right), you can write something like:

GameObject go = Assets.GetBuildingDef("ManualGenerator").BuildingComplete;

go will then be the GameObject from DoPostConfigureComplete. The other two GameObjects are for the preview and under construction.

They are added in GeneratedBuildings.LoadGeneratedBuildings, meaning GetBuildingDef won't work until after that method call. A postfix would make sense though.

As I said I haven't tried to use this, but it makes sense when exploring the source code.

Link to comment
Share on other sites

The new version includes a console file you can use it for Cheating, for hotdebugging, you could even use it to integrate c# functions and call them with the console with different parameters to debug c# code.

It also includes lua code to enable all researches on mapgeneration.

More info is autoprinted to the debug.log

 

LuaEngine.zip

Link to comment
Share on other sites

On 7/1/2019 at 6:35 PM, Nightinggale said:

 

I wonder if that is doable and how much can be modded using lua only if we go that way.

Do you have any more suggestions what to expose to lua? I have some stuff now and need more can expose classes or write functions to expose.

Maybe you have some ideas too @trevice

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...