• 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.

NoahAvrum

Recruit
Jun 3, 2016
2
0
I am new to Lua so sorry if this is very trivial but I cannot seem to get the math functions to work.
I have a number stored as a variable and I want to truncate it and display the truncated result.

Below is my example code:

function OnMsg.NewHour()
local Var_a = 1234.567
local Var_b = math.floor (Var_a)
AddCustomOnscreenNotification ("NewMSG", My Truncated Variable", Var_b)
end

Nothing gets displayed.
What am I doing wrong?

Also, can you declare Constants? I can't seem to find anything about that.

Thanks so much,
Noah
 
AddCustomOnscreenNotification ("NewMSG", My Truncated Variable", Var_b)

Your notification is incomplete and missing a quotes. Here is the format that you'll want to use to create a Notififcation Icon:

function myNotificationFunction()
CreateRealTimeThread(function()
AddCustomOnScreenNotification("notificationInternalID",
T{"notification1stLine"},
T{"notification2ndLine"},
"UI/Icons/Notifications/placeholder_2.tga",
functionToCallOnClickWithoutFinalParenthesis,
{ defineNecessaryVariablesHere,
expiration = 100000,
priority = "Important",
})
end)
end​

priority can be Normal, Important... and I think Critical?
You can also use custom icons if you like, but that requires a little bit more in the way of code. Otherwise, search out the images/Icons/Notifications folder for other options.

...and yes, this CreateRealTimeThread thing happens inside of your own function.
 
Thank you for replying but your answer only muddied the waters and now I am more confused.

Could you get me a more specific example using the math.floor function?
Also I am not clear which parts are pseudo code and which parts are syntax code from your answer.
Would it be possible to give the answer as a working message rather than pseudo code as it is not clear.

Thanks so much,
Noah
 
math functions dont work.

Also sin and cos are defined differently.

use floatfloor(float)

An example from my wind fluctuation code:

local wind_fluctuation_period = rawget(_G, "ModConfig") and ModConfig:Get("Hard Mode", "wf_period") or 32 --in hours (25h = 1 day)
local wind_fluctuation_min_production = rawget(_G, "ModConfig") and ModConfig:Get("Hard Mode", "wf_min_prod") or 40 -- in percentage of Base
local wind_fluctuation_amplitude = rawget(_G, "ModConfig") and ModConfig:Get("Hard Mode", "wf_amplitude") or 60 -- in percentage of Base



self:SetBase("electricity_production", MulDivRound(50 + production_bonus, floatfloor(wind_fluctuation), 100))
self:UpdateWorking()
self:SetAnimSpeedModifier(Min(floatfloor((300 + 3 * production_bonus)*wind_fluctuation), 1100))
 
Last edited: