Page 2 of 2

Re: Help, game error - no character

Posted: Mon Apr 11, 2022 12:44 am
by Pi-C
sdgmlj wrote: Mon Apr 11, 2022 12:17 am
Pi-C wrote: Sun Apr 10, 2022 8:00 pm Also, there's this at the top of scripts/respawn.lua:

Code: Select all

--custon event
--/c remote.call("space-exploration", "get_on_player_respawned_event")
--script.on_event(remote.call("space-exploration", "get_on_player_respawned_event"), my_event_handler)
So you must add another function to your remote interface a handler for SE's custom event. But thanks for finding this! This interferes with my mod as well, so now I know about it, I can fix it. :-)
I don't quite understand how I can add it
Like this:

Code: Select all

  if remote.interfaces["space-exploration"] and
      remote.interfaces["space-exploration"]["get_on_player_respawned_event"] then

    local event_id = remote.call("space-exploration", "get_on_player_respawned_event")
    
    script.on_event(event_id, function(event)
    	game.print("SE has respawned a player!\nEvent data: "..serpent.block(event))
    end)

  end

Re: Help, game error - no character

Posted: Mon Apr 11, 2022 1:13 am
by sdgmlj
Pi-C wrote: Mon Apr 11, 2022 12:44 am
sdgmlj wrote: Mon Apr 11, 2022 12:17 am
Pi-C wrote: Sun Apr 10, 2022 8:00 pm Also, there's this at the top of scripts/respawn.lua:

Code: Select all

--custon event
--/c remote.call("space-exploration", "get_on_player_respawned_event")
--script.on_event(remote.call("space-exploration", "get_on_player_respawned_event"), my_event_handler)
So you must add another function to your remote interface a handler for SE's custom event. But thanks for finding this! This interferes with my mod as well, so now I know about it, I can fix it. :-)
I don't quite understand how I can add it
Like this:

Code: Select all

  if remote.interfaces["space-exploration"] and
      remote.interfaces["space-exploration"]["get_on_player_respawned_event"] then

    local event_id = remote.call("space-exploration", "get_on_player_respawned_event")
    
    script.on_event(event_id, function(event)
    	game.print("SE has respawned a player!\nEvent data: "..serpent.block(event))
    end)

  end
Such a mistake has occurred:
Attempt to remote call outside of an event.
stack traceback:
[C]: in function 'call'

Re: Help, game error - no character

Posted: Mon Apr 11, 2022 6:44 am
by Pi-C
sdgmlj wrote: Mon Apr 11, 2022 1:13 am
Such a mistake has occurred:
Attempt to remote call outside of an event.
stack traceback:
[C]: in function 'call'
Oh, of course! I've defined all my event handlers in a function that is called from script.on_init, script.on_configuration_changed, and script.on_load. So something like this should work for:

Code: Select all

local function add_se_respawn_event()
  if remote.interfaces["space-exploration"] and
      remote.interfaces["space-exploration"]["get_on_player_respawned_event"] then

    local event_id = remote.call("space-exploration", "get_on_player_respawned_event")
    
    script.on_event(event_id, function(event)
    	game.print("SE has respawned a player!\nEvent data: "..serpent.block(event))
    end)

  end
end


script.on_init(function()
  add_se_respawn_event()

  ...
  
end)


script.on_configuration_changed(function(event)
  add_se_respawn_event()

  ...
end)


script.on_load(function()
    add_se_respawn_event()

  ...

end)

Re: Help, game error - no character

Posted: Mon Apr 11, 2022 7:11 am
by sdgmlj
Pi-C wrote: Mon Apr 11, 2022 6:44 am
sdgmlj wrote: Mon Apr 11, 2022 1:13 am
Such a mistake has occurred:
Attempt to remote call outside of an event.
stack traceback:
[C]: in function 'call'
Oh, of course! I've defined all my event handlers in a function that is called from script.on_init, script.on_configuration_changed, and script.on_load. So something like this should work for:

Code: Select all

local function add_se_respawn_event()
  if remote.interfaces["space-exploration"] and
      remote.interfaces["space-exploration"]["get_on_player_respawned_event"] then

    local event_id = remote.call("space-exploration", "get_on_player_respawned_event")
    
    script.on_event(event_id, function(event)
    	game.print("SE has respawned a player!\nEvent data: "..serpent.block(event))
    end)

  end
end


script.on_init(function()
  add_se_respawn_event()

  ...
  
end)


script.on_configuration_changed(function(event)
  add_se_respawn_event()

  ...
end)


script.on_load(function()
    add_se_respawn_event()

  ...

end)
OK, the problem is solved. Thank you