• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

rob771532

Recruit
Jun 8, 2019
5
0
Hello,

This is likely to be a pretty straight-forward issue, and I'm a modding/LUA newbie, but:

I'd like a couple of pointers to the right direction if possible, please.

I'm trying to develop a mod which adds another number to use alongside the Green Planet terraforming DLC. Mainly just as a learning tool for me, more than a serious attempt to create a viable mod. I've been relying quite heavily on the mod editor, and I suspect I'm at a point where I can't just rely on templates anymore.

Essentially, I want to add in "Radiation", (to go along with atmosphere, water, vegetation, temperature) starting at 100, and then have a researchable tech to unlock a building which slowly reduces this to zero. (Ideally, it would slowly creep back up to 100 if the building goes offline.)

I'd like to display this number on the screen somewhere at all times. In the general proximity of the other terraforming variables would be ideal, but not absolutely required.

I am already able to define an appropriate tech, and get it to unlock a building, which can then be built and attached to power, etc. Using the build template, I can get it to use a certain amount of power/material/manpower, etc. I'm fairly confident with that part, at this point.

Where I'm falling apart is creating a new variable for radiation, and how to display it on-screen. I thought it would be relatively straight-forward to define one in the mod editor, but this doesn't appear to be the case. At least, not that I can find. I could be missing something obvious.
1f615.png


I'm guessing this means I have to use LUA code to define a global variable somehow, and then figure out a way to get it to update itself every sol for as long as the number is above zero?

Has anyone had any experience with this? I'm not a complete newbie when it comes to coding. I've done a bit in my time, but it's been a while... so chances are I'll understand the concepts if not the specifics... but I'm a bit time-poor at the moment, so was hoping for a push in the right direction to help cut out some of the head-banging and get to the fun stuff more quickly.

Thanks.
 
Yeah, I don't think there's a way to add that with the mod editor, you'd need to use some lua in a Code section.
Shouldn't be too hard to add another number/icon to the infobar?

GlobalVar("SomeUniqueVarName", 100)
SomeUniqueVarName will be saved in the save file.

You could hook into the table used for the other params as well?
Code:
function CreateTerraformingBarContextObject()
  if not g_TerraformingParamsBarContextObj then
    g_TerraformingParamsBarContextObj = TerraformingParamsBarObj:new()
  end
  return g_TerraformingParamsBarContextObj
end


Hop on the modding discord if you want: https://discord.gg/FeWVN3t
 
Hop on the modding discord if you want: https://discord.gg/FeWVN3t

Thanks ChoGGi. (Incidentally, your Surviving Mars mods are invaluable, and I love them all)

That's exactly the sort of pointer that I was after. :)

I'm ashamed to say that I did check out the discord before posting here. I can just about handle Facebook (which is where I got told to check it out), but when I went to the discord I really didn't know what I was looking at. My computer experience started with valves and punch-cards, and I'm afraid that my coding experience ended with (admittedly quite a bit of) Pascal at university.

Catching up again is taking me longer than I had hoped, but it's having to happen a bit at a time due to time constraints.

I can muddle my way through understanding a good chunk of LUA if I read it, and I can adapt a function here-or-there if it is close enough to what I need, but I'm still getting to grips with the structure and conventions when writing my own. :)
 
(Sigh) Nothing's as easy as I thought. Sorry if this is coming across as too newbie, but I'm working towards the idea that at some point things will just click, and I'll start to get it. I am working my way through the reference manual, and some of the lua source code on GitHub, as suggested.


In the script.lua file in a new mod, I'm entering the following:

GlobalVar("globRadiation" , 100)
print("Rad:" , globRadiation)

My understanding is that this declares the global variable called "globRadiation", and assigns it the numerical value of 100... and that this will be available to access and/or modify in any other lua script I happen to need it in. I'd expect it to return "100" somewhere, such as in the console log... but it doesn't seem to do anything.

If I manually test this in the console by typing print("Rad:" , globRadiation)
I'm either getting "Rad: False" or "Rad: ".

If I manually enter globRadiation=100
and then print("Rad:" , globRadiation)

It pops up "Rad: 100" just as I expected it to the first time.

I'm a bit confused. And frustrated, as I thought I'd at least be able to put together the lua equivalent of BASIC's old...

10 R = 100
20 Print "Rad:";R


... without wanting to bang my head on a wall.
 
A global value is just
globalvar = 100
the GlobalVar is loaded/saved in the save file, so it's only available once you're in game.
Code:
GlobalVar("globRadiation", false)

local function StartupCode()
    -- new game, so it's false
    if not globRadiation then
        print("globRadiation new")
        globRadiation = 100
    end
   
    print("globRadiation",globRadiation)
end

-- new games
OnMsg.CityStart = StartupCode
-- saved games
OnMsg.LoadGame = StartupCode

I don't use the mod editor, nor the editor map, so if it works differently in it... got me.