Page 1 of 1
Activating lightsources to spawn a gem
Posted: Thu Feb 28, 2013 9:45 am
by Grimfan
In my continuing effort to slowly improve my scripting capabilities I have another riddle that I am having difficulty solving. Here's the scenario:
1. I have four button activate four lightsources (easy enough)
2. I have a lever I want to activate to spawn a gem, but only when all the lightsources are on.
Here's my problem:
How do I script that a lightsource is on (activated) without actually turning it on (thus making the four buttons pointless)? I tried to use terms like is activated or isActivated but that just resulted in an error or nothing happening (it may also have something to do with my placement of something small like an equal sign or brackets). Now if the lightsources were pressure plates or torch holders I wouldn't be having this problem, but lightsources are a different matter. It's probably one of those scripts that requires a part of lua I haven't touched yet (and there are MANY) or something simple that will make me bang my head repeatedly on the desk.
Also, as a side note, can you setSubtileOffset on a spawned item like so = spawn("red_gem",2,7,19,0):setSubtileOffset(0,0) or do you have to write it differently?
Your extremely grateful fan Grimfan.

Re: Activating lightsources to spawn a gem
Posted: Thu Feb 28, 2013 11:18 am
by germanny
what about spawn the lightsources with a specific ID instead place them ? so you can do entitiesAT...
Re: Activating lightsources to spawn a gem
Posted: Thu Feb 28, 2013 11:50 am
by Komag
you could have the buttons set flags. link the buttons to turn on the lights, and also to a function which reads the button id and sets the appropriate flag, or just link to the script and have it turn on the lights (cleaner):
-- btn1, btn2, btn3, btn4
-- lgt1, lgt2, lgt3, lgt4
-- lvr1
-- secret_32
-- all four buttons link to this function:
Code: Select all
function btnPress(b)
if b.id=="btn1" then lgt1:activate() lit1On = true
elseif b.id=="btn2" then lgt2:activate() lit2On = true
elseif b.id=="btn3" then lgt3:activate() lit3On = true
elseif b.id=="btn4" then lgt4:activate() lit4On = true
end
end
lit1On=false lit2On=false lit3On=false lit4On=false
function lvrPull()
if lit1On and lit2On and lit3On and lit4On then
spawn("cool_gem",party.level,party.x,party.y,party.facing)
secret_32:activate()
else
lvr1:toggle()
end
end
Re: Activating lightsources to spawn a gem
Posted: Thu Feb 28, 2013 12:28 pm
by Grimfan
Thanks hugely Komag, it works perfectly (though whenever you put levers in a script they seem to toggle too fast).
I think I'm going to put a special dedication in my first mods to you for your continuing help.
I knew this would involve boolean flags or some other area of lua I haven't touched yet. It's part of the evolution from simple scripting (alcove, torch, spawn and destroy scripts) to intermediate scripting that makes me feel slightly uneasy, not because I don't understand the concept (it's actually very straightforward) but because I'm not quite sure what part of the script goes where.
I find lua to be a strange beast (it's probably the same with other programming languages I don't know). It seems to me to be both incredibly restrictive yet incredibly flexible at the same time (though that could just be me).
I also think this sort of scenario is going to be a lot simpler to set up in LoG 2.
Re: Activating lightsources to spawn a gem
Posted: Thu Feb 28, 2013 1:21 pm
by Komag
You could have the script start a small timer (0.3s) that triggers a separate function to toggle the lever, I've done things like that to tweak the timing of stuff, to make a sound have a slight delay, etc.
Re: Activating lightsources to spawn a gem
Posted: Thu Feb 28, 2013 5:27 pm
by Ryeath_Greystalk
Komag,
I just wanted to confirm one thing,
this line here
lit1On=false lit2On=false lit3On=false lit4On=false
would run at start up because it's outside of a function, correct? Because my first thought was, from a top down perspective, you just erased the result of the button push.
Grimfan, looks like Komag solved you issue, but I thought I would toss this out. I have a room when I have 4 buttons, an altar, and 4 'color' scrolls controlling 16 colored lights (only 4 active at once max). I have 8 levers in a room the player can never get to. I use the altar / scroll / button combos to determine which lights are on and what color. The main point being I never actually control the lights, just the levers, then a script scans the lever states and sets the lights accordingly.
Re: Activating lightsources to spawn a gem
Posted: Thu Feb 28, 2013 8:43 pm
by Komag
Yes, those will be set at dungeon start, just to have the values there in place, it's my way of organizing things.