Page 233 of 400
Re: Ask a simple question, get a simple answer
Posted: Tue May 01, 2018 10:49 am
by Isaac
Curunir wrote:...is there a way to place items in an alcove and NOT have them appear inside each other?
Yes. Items have a subtileOffset that can be changed; offsetting their default position.
eg.
GameObject:setSubtileOffset(x, y)
Re: Ask a simple question, get a simple answer
Posted: Tue May 01, 2018 2:56 pm
by Curunir
minmay wrote:Your definition of the openSesame function is inside the coldDoor function - and after the attempt to call it, so of course it's nil when you attempt to call it.
I was fully convinced I put openSesame outside of the upper function! Thanks for pointing it out!
Isaac wrote:Yes. Items have a subtileOffset that can be changed; offsetting their default position.
eg.
GameObject:setSubtileOffset(x, y)
So, I place whatever I want on an alcove from inside the editor, then use the alcove item id-s to offset them that way in any script entity, outside of any function?
Re: Ask a simple question, get a simple answer
Posted: Tue May 01, 2018 9:44 pm
by bongobeat
Hi there, I got trouble with this code:
a book, when used, train the champion by 1 points in a skill. But if you already have available skillpoints, when you use this tome (it trains you by one skill and) it remove 1 skill points.
What am I missing?
Code: Select all
defineObject{
name = "tomeskill_learner",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/tome.fbx",
material = "book4",
},
{
class = "Item",
uiName = "The Incredible Mystery Of Life",
description = "A thick tome made by an old crook who teach us to better know ourself and increase our learning experience.",
gfxAtlas = "mod_assets/textures/oliveitem.tga",
gfxIndex = 13,
weight = 1.0,
gameEffect = "Gain Learner Skill +1",
traits = { "tome" },
},
{
class = "UsableItem",
sound = "level_up",
onUseItem = function(self, champion)
hudPrint(champion:getName().." gained Learner +1.")
champion:trainSkill("perfection", 1)
return true
end,
},
},
}
Re: Ask a simple question, get a simple answer
Posted: Wed May 02, 2018 2:27 am
by minmay
champion:trainSkill("perfection",1,false)
Re: Ask a simple question, get a simple answer
Posted: Wed May 02, 2018 4:52 am
by Isaac
Curunir wrote:So, I place whatever I want on an alcove from inside the editor, then use the alcove item id-s to offset them that way in any script entity, outside of any function?
Yes.
Example:
Code: Select all
for _,item in dungeon_alcove_1.surface:contents() do
item.go:setSubtileOffset(1.5,-.2)
break
end
EDIT:
You can try my experimental script for this. It seems to work well enough, though I'd love (suggestions) to improve upon it.
Just place it on the map, it finds altars, alcoves, and chests, and it jostles their contents.
Code: Select all
function jostle(container, seed) --Intended to shift the contents of chests.
if container and type(container) ~= 'table' then container = findEntity(container)
end
if seed and type(seed) == "number" then
math.randomseed(seed)
end
if not container.name:match('alcove') then
for _,items in container.surface:contents() do
items.go:setSubtileOffset((math.random()-.5)/2,(math.random()-.5)/2)
end
else local offset = 1.3
local dX, dY = getForward(container.facing)
if ((container.facing+1)%2) ~= 1 then
offset = offset * -1
end
if dX ~= 0 then dX = dX * offset end
if dY ~= 0 then dY = dY * offset end
for _,items in container.surface:contents() do
items.go:setSubtileOffset(dX+(math.random()-.5)/2,dY+(math.random()-.5)/2)
end
end
end
function string2bytes(text)
local result = ""
for x = 1, #text do
result = result..string.byte(text, x)
end
return tonumber(result)
end
for x = 1, Dungeon.getMaxLevels() do
for entity in self.go.map:allEntities(x) do
if entity.surface and entity.surface:count() > 0
then
jostle(entity.id)
end
end
end
Re: Ask a simple question, get a simple answer
Posted: Wed May 02, 2018 9:18 am
by bongobeat
minmay wrote:champion:trainSkill("perfection",1,false)
Thanks

Re: Ask a simple question, get a simple answer
Posted: Wed May 02, 2018 12:10 pm
by Curunir
One thing that keeps bugging me - why are there so many differently named instances of dungeon floor and ceiling entities in the editor? I plopped down a few side by side and could not see any immediately discernible difference.
p.s. I somehow did not see your reply to my previous question! Thanks, Isaac, I will give the script a go when I get back home! Which brings me back to an issue I've had with LUA ever since I started reading tutorials and scripts here - the use of the underscore.
"It is idiomatic in Lua to use the underscore character for throw away variables so you can simply assign it to another variable name."
"The Lua coding standard designates the underscore (_) as the standard global variable to use in place of an unused variable."
I just can't wrap my head around what that means. Is this sort of like a wildcard, anything goes replacer?
Re: Ask a simple question, get a simple answer
Posted: Wed May 02, 2018 6:01 pm
by minmay
If you call a function that returns multiple values, but you don't use all of the return values, you may end up with an unused variable. Typically people name this variable _. The most common construction you'll see is
because sometimes you don't care about the keys in a table, just the values.
The underscore doesn't have an inherent meaning in Lua, it's just a normal variable name.
Re: Ask a simple question, get a simple answer
Posted: Wed May 02, 2018 8:39 pm
by Curunir
Ah, that makes more sense, worded that way! Thank you!
Re: Ask a simple question, get a simple answer
Posted: Wed May 02, 2018 11:30 pm
by akroma222
Hey All , I have a question re Container Items...
Specifically, what would be the best/cleanest way to detect whether a champion currently has an Open (or Closed) Container Item in their Inventory ???
Reason - I'm having to re implement some of the champ menu GUI, including Containers
(I've drawn over the top of some of the games hard coded things, and now have to re implement what Ive drawn over

)
Ive not dealt with Containers extensively, but I suspect maybe...
.... a "UsableItemComponent" could be added and onUseItem hook could simply check/change/toggle a global variable ??
Ive made a few disastrous attempts at defining Containers using this^^ and similar methods to detect whether they are in an Inventory, Open/Closed etc
However, Im experiencing an acute case of deferred success

Any suggestions welcome
