Page 1 of 1

"defines.events"

Posted: Tue Jun 18, 2019 6:17 pm
by TheSAguy
Hi,

I'm trying to alter the Supply Challenge scenario and I've run into a problem.
It appears I can't have the below tow "defines.events" at the same time


Code: Select all

script.on_event(defines.events.on_tick, function(event)
and

Code: Select all

script.on_event(defines.events, function(event)
This is my current code:

Code: Select all

[code]script.on_event(defines.events.on_tick, function(event)

  if game.tick % (2) == 0 then
	remove_worms()
  end
  
	if game.tick % (60 * 60 * 1) == 0 then -- 3600 one min
		local PositionValid = game.surfaces[1].find_non_colliding_position("dune-worker", {1, 1}, 4 , 1)
			if PositionValid then
				spawn_worker = game.surfaces[1].create_entity({name = "dune-worker", position = PositionValid, force = game.forces.player})
			else	
				game.print("No Position")
			end	
	end
		
end)
and

Code: Select all

script.on_event(defines.events, function(event)
  
	story_update(global.story, event, "")
  
end)
If I combing them, my spawns don't work as intended.

Code: Select all

[code]script.on_event(defines.events.on_tick, function(event)

story_update(global.story, event, "")
  if game.tick % (2) == 0 then
	remove_worms()
  end
  
	if game.tick % (60 * 60 * 1) == 0 then -- 3600 one min
		local PositionValid = game.surfaces[1].find_non_colliding_position("worker", {1, 1}, 4 , 1)
			if PositionValid then
				spawn_worker = game.surfaces[1].create_entity({name = "worker", position = PositionValid, force = game.forces.player})
			else	
				game.print("No Position")
			end	
	end
		
end)
The "story_update" does not seem to work as intended. When clicking the "Next" button when reaching the goal does nothing.
Clicking the "Next Level" does not fire:
Image

I tried converting everything to "Factorio Standard Library", but even that caused problems with that "Next Level" button.
I could not get the game to recognize me clicking it. So basically the same issue as I'm having with the above.

I'm a little stumped as to how to proceed here.
I can attached my control here, but it's basically just being able to access "defines.events.on_tick" using the Supply Challenge Conrtol and still have that work as intended.


Thanks.

Re: "defines.events"

Posted: Tue Jun 18, 2019 6:56 pm
by eduran
Subscribing a second time to the same event will overwrite the first one.

Code: Select all

script.on_event(defines.events.on_tick, on_tick_handler(event)) -- on_tick_handler will never be called
script.on_event(defines.events, all_events_handler(event)) -- registers for ALL events, including on_tick
If you change the order around, your all_events_handler will never be called during the on_tick event.

I suggest that you only use the events you actually need, which gets around the above problem and is also better for performance:

Code: Select all

script.on_event(defines.events.on_tick, on_tick_handler(event))
local my_story_events = {
  defines.events.whatever_1,
  defines.events.whatever_2,
  ...
}  
script.on_event(my_story_events, story_event_handler(event))
Regarding the button not working: Post the code that handles that interaction, otherwise it is pretty hard to help ;)

Re: "defines.events"

Posted: Tue Jun 18, 2019 7:36 pm
by TheSAguy
Thanks Eduran!

I think it would be best if I just attached the mod.
So currently when you click on "Next Level" nothing happens.

If you wait till the time runs out, and you completed the goal, it does go to the next goal.
As I said in the OP, it's got something to do with the events I think.

Thanks again.