Jump to content

Recommended Posts

I am an absolute baboon brain when it comes to coding in LUA, I have already learned too many other coding languages and I am trying my best to pick up DST modifications.

This is my modmain.lua

local require = GLOBAL.require
local WorldEditor = TheWorld
 
require "constants"

while(true)
do
   WorldEditor:PushEvent("ms_setclocksegs", {day=6,dusk=4,night=6})
end

When running this, the server fails to start, and I have tried many variations of this code, but no matter what, if it doesn't crash, the line of code that is meant to set the clock segments does not work.


All I wish to do is for my first step into addons is to make this random mod just permanently set the clock segments to 6,4,6.

The reason I chose WorldEditor:PushEvent("ms_setclocksegs", {day=6,dusk=4,night=6}) is because as a console command it works as:
TheWorld:PushEvent("ms_setclocksegs", {day=6,dusk=4,night=6})
I presumed I could simply define a variable as TheWorld, but that doesn't appear to be the case.

Edited by Target Practice
Further Elaboration on choice of command

Can someone help me with my mod not working? (I am also a really bad Modder)

So, I tried to add a new recipe tab but it just crashes. (Dedicated server failed to start) Can someone help me.

modmain.lua

Look at the bottom in the --war robots tab. Also, disclaimer my mod is a character mod with a half resprited boltgun to it I plan on changing it completely.

7 hours ago, Leonidas IV said:

I've never seen any mod code using while, maybe that's the problem

I understand that it may be the loop but also that's not the problem.

I need to figure out how to get 

TheWorld:PushEvent("ms_setclocksegs", {day=6,dusk=4,night=6})

working again.

I honestly have no clue how to obtain "TheWorld" variable, but i have to. I know it's defined in "scripts/prefabs/world" but i'm not sure exactly how to obtain that variable.

16 hours ago, Target Practice said:

I honestly have no clue how to obtain "TheWorld" variable

You need to say that this variable is  in global scope, so you can do GLOBAL.TheWorld:PushEvent("ms_setclocksegs", {day=6,dusk=4,night=6})

18 hours ago, FruityRounds_06 said:

Can someone help me with my mod not working? (I am also a really bad Modder)

So, I tried to add a new recipe tab but it just crashes. (Dedicated server failed to start) Can someone help me.

modmain.lua 3.41 kB · 1 download

Look at the bottom in the --war robots tab. Also, disclaimer my mod is a character mod with a half resprited boltgun to it I plan on changing it completely.

You better create a new topic

@Target Practice
Oh, I think I might see the issue.  It’s just a hunch, but I did use the While command.  Basically it loops as long as the condition is true.  If you’d told it to loop While True, it may just be looping forever.  Perhaps that’s the issue?

On 1/9/2022 at 6:43 PM, FurryEskimo said:

@Target Practice
Oh, I think I might see the issue.  It’s just a hunch, but I did use the While command.  Basically it loops as long as the condition is true.  If you’d told it to loop While True, it may just be looping forever.  Perhaps that’s the issue?

@FurryEskimo If that's the case, do you recommend another way to have this mod work as intended?
It's only intention is to set the time of day so that it never changes from what the player set it's to. I've done the setup for config and fixed everything except for the fact it crashes from using a while(true) loop. I'm pretty certain the command even works in game, without the crashing part.

EDIT: I just ran the mod without a while(true) loop, it's crashing anyways, the dedicated server fails to start with this as the modmain:

local require = GLOBAL.require
 
require "constants"


GLOBAL.TheWorld:PushEvent("ms_setclocksegs", {day=6,dusk=4,night=6})

 

Edited by Target Practice
Crash reason changed

At the moment when the modmain is loaded, TheWorld doesn't exist, it only exists when the server is started.

Try adding it in a AddSimPostInit

AddSimPostInit(function()
	GLOBAL.TheWorld:PushEvent("ms_setclocksegs", {day=6,dusk=4,night=6})
end)

From there on you can either do a periodic task or something else, depending on how you want to do it.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...