Page 1 of 1

Putting out torches in torch holders

Posted: Mon Jun 17, 2013 7:19 pm
by Ulfsark
Hey guys, I am trying to put out all of the torches in a room except for the one the player is holding, so this would only put out the ones that are in torch holders.

I looked around and could not find anything on how to disable ones in torch holders. Simply destroying the entity would remove the torch holder as well correct? If anybody could point me in the right direction I would appreciate it.

Thanks!

Re: Putting out torches in torch holders

Posted: Mon Jun 17, 2013 7:28 pm
by Komag
Destroy all torches in torchholder square, then add dead torch

Re: Putting out torches in torch holders

Posted: Mon Jun 17, 2013 8:54 pm
by Ulfsark
Komag wrote:Destroy all torches in torchholder square, then add dead torch
Are torch holders considered containers? If I were to add a dead torch I would use something akin to this correct?

Code: Select all

torchholder_id:addItem(deadtorch_id)

Re: Putting out torches in torch holders

Posted: Mon Jun 17, 2013 10:41 pm
by Komag
Yeah, it's right there in the scripting reference, but you need to spawn a torch, set its fuel to 0, and add it, all on the same line

Re: Putting out torches in torch holders

Posted: Tue Jun 18, 2013 4:51 am
by JohnWordsworth
Unfortunately, I don't think torchholders have a removeItem() method. It might do, but it's not documented in the scripting reference (they might have forgotten to add it, or it might not be supported).

If it's not supported, I think you could do the following:

Code: Select all

function putOutTorchInHolder(holder) 
  if ( holder == nil ) then
    print("Attempted to put out torch in a nil torchholder!");
    return nil;
  end

  if ( holder:hasTorch() ) then
    local id, level, x, y, facing = holder.id, holder.level, holder.x, holder.y, holder.facing;
    holder:destroy();
    holder = spawn("torch", level, x, y, facing, id);
    holder:addItem(spawn("torch"):setFuel(0));
  end
end
Then just call the above method from any script doing putOutTorchInHolder(torchholder_1);

Note, this is untested, so might not work - but in principal, I think it should!

Re: Putting out torches in torch holders

Posted: Tue Jun 18, 2013 5:45 pm
by Ulfsark
Sounds good, Thanks a lot guys, I will let you know what I manage to get working if anything.

Thanks!