Page 1 of 1

beacons and essences

Posted: Fri Oct 23, 2015 12:27 pm
by FeMaiden
if I wanted to do something like have the beacon of air on one level, then the beacon of fire on a different level etc...

and when the player places the correct essence on all 4 beacons then places the essence of balance on the beacon of balance, a teleporter appears.

how would I do this?
I need each beacon to respond only to the correct essence, and then when placing the balance essence, it checks for the conditions of all 4 essences placed correctly to be true.

I know this is a scripting thing.

does the game keep track of it if the beacons are all on different levels, like the fire is at x1 y1 z1 and the air is at x3 y1 z1 and then the balance beacon is at x2 y2 z1?

I'm still a noob to lua scripting. if it was me, i'd try to establish some global variable, that updates whenever a correct essence is placed or removed and when it reaches a certain value, the event occurs

maybe with a counter? like set the value to 5 and whenever the correct essence is placed on the beacons it decrements it by 1 and when all the essences are placed it activates the teleporter.

so i'd need it to say like for the fire beacon, something like "if essence_fire = true then decrememt the counter, else do nothing" (keep in mind i have absolutely no idea what i'm talking about lol)


perhaps this has all been explained elsewhere, but i don't know how to search it out, if you know a link to the answer, you can just direct me there.

Re: beacons and essences

Posted: Fri Oct 23, 2015 1:16 pm
by Drakkan
no need to complicate things... you can use for example script below, I am sure there could be more skilled scripts, but this should do.

just insert lua script, insert code bellow and connect from each beacon onInsert and Onremove hook to the script for function checkSolution.


Code: Select all

function checkSolution()
local green = false
local blue = false
local red = false
local yellow = false

for _,itm in greenaltr.surface:contents() do         -- name your beacon somehow and rewrite the same name here
if itm.go.name == "green_gem" then                   -- rewrite required essence name instead gem
			green = true
			break
		end
	end

	for _,itm in bluealtr.surface:contents() do
		if itm.go.name == "blue_gem" then
			blue = true
			break
		end
	end
		for _,itm in redaltr.surface:contents() do
		if itm.go.name == "red_gem" then
			red = true
			break
		end
	end

		for _,itm in yellowaltr.surface:contents() do
		if itm.go.name == "yellow_gem" then
			yellow = true
			break
		end
	end

if green and blue and red and yellow then
		dungeon_door_name_what_you_need.controller:open()   -- name your doors / whatever you need to open
else
		dungeon_door_name_what_you_need.controller:close()  -- the same
	end
end

Re: beacons and essences

Posted: Sat Oct 24, 2015 12:34 am
by FeMaiden
okay. thanks for the script.

will this work even if the beacons are on different map levels? like for example if I have one beacon in the plains to the east but another one deep in the crystal mines to the north west?


also, are the indentation formatting essential to make the script run correctly or are the indents just to make it easier for the programmer to read?



edit1
thank you, this worked...except because I was using the beacons, i had to change "surface" to "socket" and i was using a teleporter so I had to put at the end, teleporter_name.controller:activate()

and i puzzled it out for 15 minutes trying to figure out why it wouldn't work...and it turned out I had a typo, i misspelled one of the essences names...


edit2

hmm, i have another problem.
this script works if all the beacons are on the same map. but i did a test and moved one of the beacons (beacon_air) to the next map over and reconnected it and I get an error

"attempt to index 'global beacon_air' a nil value X"

it works if they are all on the same map, but not if the beacon is on a different map.


edit3

oops, i'm dumb...I just forgot to rename my beacon, the beacon was named beacon_air_1 and I was trying to reference beacon_air


this works so i can finally have my epic world spanning puzzle :)