[ Solved ]An item fuel that uses energy stored on equipment grid to power vehicles

This is the place to request new mods or give ideas about what could be done.
N0TZ3R0
Inserter
Inserter
Posts: 22
Joined: Tue Dec 29, 2020 1:36 am
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post by N0TZ3R0 »

Yep it's buffering

Energy: 1.0MJ/1.0MJ

PFQNiet
Fast Inserter
Fast Inserter
Posts: 235
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post 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!

N0TZ3R0
Inserter
Inserter
Posts: 22
Joined: Tue Dec 29, 2020 1:36 am
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post by N0TZ3R0 »

Sir, it's unregistering the vehicles ( I can c their IDs ) but not registering, I think it's something with onBuilt.

N0TZ3R0
Inserter
Inserter
Posts: 22
Joined: Tue Dec 29, 2020 1:36 am
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

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

PFQNiet
Fast Inserter
Fast Inserter
Posts: 235
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post 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!

N0TZ3R0
Inserter
Inserter
Posts: 22
Joined: Tue Dec 29, 2020 1:36 am
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post 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

N0TZ3R0
Inserter
Inserter
Posts: 22
Joined: Tue Dec 29, 2020 1:36 am
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post 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 ?

PFQNiet
Fast Inserter
Fast Inserter
Posts: 235
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post 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?

N0TZ3R0
Inserter
Inserter
Posts: 22
Joined: Tue Dec 29, 2020 1:36 am
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post by N0TZ3R0 »

Oh I c, it was my fault sorry, I checked it again and I changed a wrong value, so not it's fully working.

PFQNiet
Fast Inserter
Fast Inserter
Posts: 235
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post by PFQNiet »

I feel like I've just accidentally written an entire mod without having Factorio available XD

N0TZ3R0
Inserter
Inserter
Posts: 22
Joined: Tue Dec 29, 2020 1:36 am
Contact:

Re: An item fuel that uses energy stored on equipment grid to power vehicles

Post by N0TZ3R0 »

Yep sir haha, I'll give u credit when I post it.


Post Reply

Return to “Ideas and Requests For Mods”