Page 35 of 396
Re: Ask a simple question, get a simple answer
Posted: Mon Dec 22, 2014 8:38 am
by minmay
Davenfal wrote:That worked perfectly, thanks for the help! I do have another question:
Code: Select all
function openNorthGates()
if NorthGate.onInsertItem(NorthGate, "essence_balance_1") then
north_gate1.door:open();
north_gate2.door:open();
else
north_gate1.door:close();
north_gate2.door:close();
end
end
For some reason, the field onInsertItem is returning a nil value, am I calling it wrong or is my mistake elsewhere?
The onInsertItem hook is called when an item is inserted in the socket. It returns false if the item should be rejected (not placed in the socket), and something esle if it shouldn't be (generally true or nil). Circumstances under which it makes sense to manually call it yourself are
extremely esoteric. Furthermore, "essence_balance_1" is a string, not an item.
Grimfan wrote:Sockets normally only take a single item like a torch (they are not like altars and alcoves). Each of the beacons only accepts a single essence as far as I know.
The beacons accept literally any item in the game. You need to check the item's name:
Code: Select all
function openNorthGate()
local item = NorthGate.socket:getItem()
if item and item.go.name == "essence_balance" then
northgate1.door:open()
northgate2.door:open()
end
end
edit: typo fix
Re: Ask a simple question, get a simple answer
Posted: Mon Dec 22, 2014 8:50 am
by Davenfal
minmay wrote:Davenfal wrote:That worked perfectly, thanks for the help! I do have another question:
Code: Select all
function openNorthGates()
if NorthGate.onInsertItem(NorthGate, "essence_balance_1") then
north_gate1.door:open();
north_gate2.door:open();
else
north_gate1.door:close();
north_gate2.door:close();
end
end
For some reason, the field onInsertItem is returning a nil value, am I calling it wrong or is my mistake elsewhere?
The onInsertItem hook is called when an item is inserted in the socket. It returns false if the item should be rejected (not placed in the socket), and something esle if it shouldn't be (generally true or nil). Circumstances under which it makes sense to manually call it yourself are
extremely esoteric. Furthermore, "essence_balance_1" is a string, not an item.
Grimfan wrote:Sockets normally only take a single item like a torch (they are not like altars and alcoves). Each of the beacons only accepts a single essence as far as I know.
The beacons accept literally any item in the game. You need to check the item's name:
Code: Select all
function openNorthGate()
local item = NorthGate.socket:getItem()
if item and item.name == "essence_balance" then
northgate1.door:open()
northgate2.door:open()
end
end
I appreciate the explanations, they helped clear up quite a bit of what was confusing me. The script no long throws me an error!
Re: Ask a simple question, get a simple answer
Posted: Mon Dec 22, 2014 9:13 am
by Grimfan
Sorry about before Davenfal. I was confusing the visual effects of the beacon with what it actually accepts.
This works in my mod (it opens the door):
Code: Select all
function revealTheWay()
local e = beacon_air_1.socket:getItem()
if e.go.name == "essence_air" then
castle_secret_door_83.door:open()
end
end
And yes I have 83 secret castle doors in my mod.
Re: Ask a simple question, get a simple answer
Posted: Mon Dec 22, 2014 9:41 am
by minmay
Grimfan wrote:Code: Select all
function revealTheWay()
local e = beacon_air_1.socket:getItem()
if e.go.name == "essence_air" then
castle_secret_door_83.door:open()
end
end
This will crash if the beacon does not have an item in it, since you can't index nil values. That's the purpose of checking that the item exists in the function I posted (which had a different error in it that I've fixed, sorry).
Re: Ask a simple question, get a simple answer
Posted: Mon Dec 22, 2014 9:49 am
by Grimfan
I now know that it causes a crash, but why was it working for me? I could leave the beacon empty and nothing happens (it doesn't crash). Why was that the case?
Well, time to change some scripts around.
Re: Ask a simple question, get a simple answer
Posted: Mon Dec 22, 2014 10:06 am
by Davenfal
I'm encountering a really strange oddity. whenever I set an essence onto a beacon whose height is lower than zero, the essence doesn't properly adjust its height to that of the beacon and instead floats at a height of zero. Is there an easy way to change it's position after it's placed?
Re: Ask a simple question, get a simple answer
Posted: Mon Dec 22, 2014 5:44 pm
by minmay
Grimfan wrote:I now know that it causes a crash, but why was it working for me? I could leave the beacon empty and nothing happens (it doesn't crash). Why was that the case?
Depends when you were calling that function. If you were only calling it when an item is inserted then it always had an item in it.
Davenfal wrote:I'm encountering a really strange oddity. whenever I set an essence onto a beacon whose height is lower than zero, the essence doesn't properly adjust its height to that of the beacon and instead floats at a height of zero. Is there an easy way to change it's position after it's placed?
You wouldn't find this strange at all if you looked at the definition in the asset pack, specifically the onUpdate hook for the beacon light:
Code: Select all
onUpdate = function(self)
local socket = self.go.socket
if socket:count() > 0 then
local it = socket:getItem()
if it.go.name == "essence_fire" then
it.go:setWorldPositionY(0.85 + math.sin(Time.currentTime()) * 0.05)
elseif it:hasTrait("essence") then
it.go:setWorldPositionY(0.75)
end
end
end,
As you can see, it sets the essence's position independently of the beacon's position. You should be able to change this behaviour by doing something like this:
Code: Select all
onUpdate = function(self)
local socket = self.go.socket
if socket:count() > 0 then
local it = socket:getItem()
if it.go.name == "essence_fire" then
it.go:setWorldPositionY(self.go:getWorldPositionY() + 0.85 + math.sin(Time.currentTime()) * 0.05)
elseif it:hasTrait("essence") then
it.go:setWorldPositionY(self.go:getWorldPositionY() + 0.75)
end
end
end,
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 23, 2014 10:54 pm
by Periodiko
I'm trying to relearn how the scripting works in this game and I was wondering if you could help me with some simple stuff.
Ya'll know about the horn you blow at the beach to summon the viper roots for the boss battle? Well it works by the following script embedded in it's object definition:
Code: Select all
onAttack = function(self)
for e in party.map:entitiesAt(party.x, party.y) do
if e.script and e.script.blowTheHorn then
e.script:blowTheHorn()
end
end
playSound("blow_horn")
end,
How does "in" work?
Also, a maybe slightly more involved question: if I wanted to use a similar function in an object definition to run a level script object, how would I do that? Say I had a horn that when you blew it, it ran a script that opened all the doors in the level and started a boss-fight, for example, but it happened regardless of where you were on the level.
Re: Ask a simple question, get a simple answer
Posted: Tue Dec 23, 2014 11:51 pm
by GoldenShadowGS
Periodiko wrote:I'm trying to relearn how the scripting works in this game and I was wondering if you could help me with some simple stuff.
Ya'll know about the horn you blow at the beach to summon the viper roots for the boss battle? Well it works by the following script embedded in it's object definition:
Code: Select all
onAttack = function(self)
for e in party.map:entitiesAt(party.x, party.y) do
if e.script and e.script.blowTheHorn then
e.script:blowTheHorn()
end
end
playSound("blow_horn")
end,
How does "in" work?
Also, a maybe slightly more involved question: if I wanted to use a similar function in an object definition to run a level script object, how would I do that? Say I had a horn that when you blew it, it ran a script that opened all the doors in the level and started a boss-fight, for example, but it happened regardless of where you were on the level.
Its sort of like a list of everything in a certain container. this part of the script will repeat as many times as the number of objects that the container contains. For this case, e = everything on tile the party is standing at.
Here is an example I did:
I want to see if there is any entity with platform component at a certain spot, at a certain elevation.(bridges, etc)
elevation, hasbridge are my variables, don't worry about them
Code: Select all
for i in party.map:entitiesAt(myx,myy) do
if i.elevation == elevation and i:getComponent("platform") then
if i.platform:isEnabled() then
hasbridge = true
end
end
end
Re: Ask a simple question, get a simple answer
Posted: Wed Dec 24, 2014 5:15 pm
by Thorham
How can I set the scale of a custom GUI? By default, elements like fonts always have the same size, regardless of the screen resolution. Any way to change this?