Jump to content

Recommended Posts

Hi,

How come the print below is "inst.prefab is forest"???
(inst.prefab should be myMod)

This is in my myMod.lua:

Quote

inst:ListenForEvent("seasonChange", function(inst, data)
        if (inst.prefab ~= nil) then
            print ("inst.prefab is "..inst.prefab) --why does this return "forest"???
        end

...
    end, GetWorld())

If that's correct, how do I send "myMod" inst inside this function inside ListenForEvent?

Thanks.

Edit: I have a feeling it's the "GetWorld()" part. What is this... is it the scope?

Edit2: Changing it from

Quote

inst:ListenForEvent("seasonChange", function(inst, data)

To

Quote

inst:ListenForEvent("seasonChange", function(world, data)

fixed it. How?

Edited by SenL

Structure of the ListenToEvent function:

function EntityScript:ListenForEvent(event, fn, source)

Where source is optional, if not passed, it will be the calling entity.

So when the event is pushed, the function (fn) that was passed receives source and the push date. When you set a source, the first parameter of your function will be the source! There is no way for your entity to be pushed by the world! It only warns you that the season has changed!

What you fixed is that you were overriding the value of inst (your item), with the world, by calling it "inst" too.

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