Page 2 of 2
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sat Jan 02, 2021 11:38 pm
				by N0TZ3R0
				Yep it's buffering 
Energy: 1.0MJ/1.0MJ
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 10:46 am
				by PFQNiet
				Okay, let's try some debugging.
Inside the "onBuilt", just before the "end", insert:
Code: Select all
game.print("Registered vehicle "..entity.unit_number)
Likewise inside "onMined", add:
Code: Select all
game.print("Unregistered vehicle "..entity.unit_number)
This should cause a chat message to appear when you place or remove vehicles. If this works, then the registration part is working fine and the problem lies in the onTick part, so this is a great way to divide up the debugging problem!
 
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 12:21 pm
				by N0TZ3R0
				Sir, it's unregistering the vehicles ( I can c their IDs ) but not registering, I think it's something with onBuilt.
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 12:25 pm
				by N0TZ3R0
				If I remove this line do to a test:
 if not (entity and entity.valid and isVehicle(entity)) then return end  ( it's in control.lua )
And place a vehicle, I get an error:
O mod ZElectricEngine (0.0.1) causou um erro não recuperável.
Por favor, reporte este erro ao autor do mod.
Error while running event ZElectricEngine::on_built_entity (ID 6)
__ZElectricEngine__/control.lua:21: attempt to index local 'entity' (a nil value)
stack traceback:
	__ZElectricEngine__/control.lua:21: in function 'handler'
	__core__/lualib/event_handler.lua:47: in function <__core__/lualib/event_handler.lua:45>
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 12:50 pm
				by PFQNiet
				Aha, I see.
Code: Select all
  local entity = event.entity or event.built_entity
This line is wrong. It should be:
Code: Select all
  local entity = event.entity or event.created_entity
Whoops!
 
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 1:00 pm
				by N0TZ3R0
				Some good News, It's working perfectly fine as I wanted, I will remove the debugging and change somethings then release it, bro thanks a lot for the help, I'll put your name there haha
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 1:07 pm
				by N0TZ3R0
				Only one thing I notice is that it drains power while the vehicle isn't used, Is there a way to add a check if player is inside then debit the energy ?
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 2:19 pm
				by PFQNiet
				It's supposed to drain power to fill up the fuel bar. Once the fuel bar is full, "missing" should be 0 so it shouldn't be draining any power.
Might be worth adding this debug line after the "local missing = CAPACITY - ..." line:
Code: Select all
game.print("Vehicle "..car.unit_number.." is missing "..missing.." energy")
That number should start out at a million (1MJ) and gradually drop to 0 as the generator fills the fuel bar. Can you test that?
 
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 4:06 pm
				by N0TZ3R0
				Oh I c, it was my fault sorry, I checked it again and I changed a wrong value, so now it's fully working.
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 4:55 pm
				by PFQNiet
				I feel like I've just accidentally written an entire mod without having Factorio available XD
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 4:57 pm
				by N0TZ3R0
				Yep sir haha, I'll give u credit when I post it.
			 
			
					
				Re: An item fuel that uses energy stored on equipment grid to power vehicles
				Posted: Sun Jan 03, 2021 6:11 pm
				by N0TZ3R0