Jump to content

Recommended Posts

Hi, I was curious if there is a difference in putting "inst.entity:SetPristine()" either before or after "TheWorld.ismastersim"?

Some mods have SetPristine() before TheWorld.ismastersim and some do SetPristine() after.

Also what is the difference between "local function fn(Sim)" and "local function()". Does putting Sim in between () make a difference too?

Some examples of what I mean are down below. Thank you for reading.

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end    

or 

    if not TheWorld.ismastersim then
        return inst
    end    

    inst.entity:SetPristine()

Also

local function fn(Sim)

and 

local function fn()

 

"inst.entity:SetPristine()" should be before "if not TheWorld.ismastersim then return inst end"

This tells the client and server that whatever follows should not affect the client's state in any way and that only components should really exist beyond the point.

It's an optimization for networking, I believe.

 

The text between the parenthesis is called an argument.

So you can call "fn" with the argument of anything, and in the scope of the function "Sim" will be the variable passed.

 

"local function()" cannot exist as it does not define the function name which is a requirement in LUA.

On 9/20/2016 at 3:49 AM, CarlZalph said:

"inst.entity:SetPristine()" should be before "if not TheWorld.ismastersim then return inst end"

This tells the client and server that whatever follows should not affect the client's state in any way and that only components should really exist beyond the point.

It's an optimization for networking, I believe.

 

The text between the parenthesis is called an argument.

So you can call "fn" with the argument of anything, and in the scope of the function "Sim" will be the variable passed.

 

"local function()" cannot exist as it does not define the function name which is a requirement in LUA.

Thank you for explaining. Also I just recently viewed the thread "Getting started with modding DST..." by Rezecib and I noticed he mentioned this:

 

    inst.entity:SetPristine() 

"This basically says "everything above this was done on both the client on the server, so don't bother networking any of that". This reduces a bit of the bandwidth used by creating entities. I can't think of a case where you wouldn't want this immediately after the "if not TheWorld.ismastersim then return inst end" part, which is where you'll see it in the game's code."

 

I'm now confused again where SetPristine() goes before or after. Is he wrong?

9 hours ago, Luis95R said:

I'm now confused again where SetPristine() goes before or after. Is he wrong?

It should always go before the ismastersim return check so that it runs for both the client and server.

 

Check out any prefab provided by Klei and it is done this way.

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

 

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