Page 343 of 396

Re: Ask a simple question, get a simple answer

Posted: Sun Mar 15, 2020 11:39 am
by SluisE
Isaac wrote: Sun Mar 15, 2020 4:49 am
SluisE wrote: Sat Mar 14, 2020 8:22 pm Use destroyDelayed instead of destroy. That way the item is destroyed when you end the function.
This is very good; best practice I think. (And thanks for the comment on it. 8-) )

But what really happens under the hood when the object is destroyed (by the usual method)? Is its position shifted? Can an entry be missed?

It seems to make sense to almost always (or to only) use destroyDelayed just as a matter of course, because it does bypass some nasty crashes in some situations. But does anyone know (or can reasonably speculate on) what could actually happen if an object gets destroyed in the iterator loop—and is never accessed again? Could it actually crash?

minmay will tell you (with good reason) that the monster.contents iterator is damaged, or broken; it DOES (or can? IIRC) cause crashes when it returns nil. I never had a crash with it after I added a 'pocket_lint' item before using it. :lol:
I don't know what happens internally, but you could try this test (I would do it myself but right now I'm too ill/tired/whatever to turn on the computer):

Put an alcove in your dungeon and put three different items in it.
Put a button next to it and connect it to a script.
In the script you do three things:
1) Iterate throught the contents and hudPrint the item-names. Shouldn't be too surprising.
2) Iterate through the contents and hudPrint the names, but destroy the first item (not destroyDelayed) after hudPrinting it. Are all three items now printed or only two, and if so, which two?
3) As in 2, but apart form destroying the item also spawn and add a new item. What happens now?

The answers might give you an idea (but no certainty) about the inner workings of the iteration.

Re: Ask a simple question, get a simple answer

Posted: Sun Mar 15, 2020 10:48 pm
by minmay
Basically, the contents of a SurfaceComponent are in an array, and new items get added to the end of the array, and removing an item will shift down the positions of the other items in the array. I think destroying an item in the middle of iterating over the contents with contents() will indeed result in skipping the next item in the array, which is not something you want.

destroyDelayed() is perfect for this situation; it destroys the object at the end of the frame instead of immediately.

Re: Ask a simple question, get a simple answer

Posted: Mon Mar 16, 2020 2:48 am
by Eleven Warrior
I'm using this code (Below) and have added Else and the line: hudPrint("I dont want that "..item:getUiName()) but the problem is it wont work with this line added. What is going wrong?

Code: Select all

--- Single Quest item for reward ---
function SpawnRewards()
  local s = altar_2.surface
    for _,e in s:contents() do
      if e.go.name == "dagger" then
        e.go:destroy()
	s:addItem(spawn("fire_gauntlets").item)
	s.go:spawn('teleportation_effect')
	     else
	hudPrint("I dont want that "..item:getUiName())
	  end
	end
end

Re: Ask a simple question, get a simple answer

Posted: Mon Mar 16, 2020 6:12 am
by Isaac
It cannot work; item:getUiName() —by itself— refers to an object that doesn't exist in the function. You need to use the component of e for the item name; e.go.item:getUiName().

Code: Select all

function SpawnRewards()
  local s = altar_2.surface
    for _,e in s:contents() do
      if e.go.name == "dagger" then
        e.go:destroyDelayed()
		s:addItem(spawn("fire_gauntlets").item)
		s.go:spawn('teleportation_effect')
	  else
		hudPrint("I dont want that "..e.go.item:getUiName())
	  end
	end
end

Re: Ask a simple question, get a simple answer

Posted: Tue Mar 17, 2020 9:47 am
by bongobeat
Is there some better quality log2 portrait? At least 256x256?
Hidden in the dat file, or never published?

Re: Ask a simple question, get a simple answer

Posted: Wed Mar 18, 2020 3:59 am
by Eleven Warrior
Has anyone got a bunch or Potion objects? I need some new potion for my mod there are only a small amount with the assest pack ty :)

Re: Ask a simple question, get a simple answer

Posted: Wed Mar 18, 2020 4:35 am
by minmay
There are larger (but jpeg) versions of a few of the portraits here: http://www.grimrock.net/2013/08/16/maki ... portraits/

Re: Ask a simple question, get a simple answer

Posted: Wed Mar 18, 2020 10:12 am
by Eleven Warrior
I trying to get this potion to work when the champ drinks it the food bar should go up but, this potion here is not working Help...

defineObject{
name = "potion_restore",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/flask.fbx",
},
{
class = "Item",
uiName = "Potion of Restoration",
gfxIndex = 148,
weight = 0.3,
stackable = true,
description = "Drinking the potion will cause the champion to be bestowed with a torrent of powerful energy and healing that cleanses ailments and provides nourishment.",
traits = { "potion" },
},
{
class = "UsableItem",
sound = "consume_potion",
emptyItem = "flask",
onUseItem = function(self, champion)
playSound("consume_potion")
champion:regainFood(350) --- This wrong it crashes
return true
end,
},
},
tags = { "zim_assets" },
}

Re: Ask a simple question, get a simple answer

Posted: Wed Mar 18, 2020 2:35 pm
by bongobeat
minmay wrote: Wed Mar 18, 2020 4:35 am There are larger (but jpeg) versions of a few of the portraits here: http://www.grimrock.net/2013/08/16/maki ... portraits/
Thanks but I already have those.

May I ask how you did the dm portraits in the dm ressource asset?

Re: Ask a simple question, get a simple answer

Posted: Wed Mar 18, 2020 2:40 pm
by bongobeat
Eleven Warrior wrote: Wed Mar 18, 2020 3:59 am Has anyone got a bunch or Potion objects? I need some new potion for my mod there are only a small amount with the assest pack ty :)
you can find different flasks in there:
https://www.nexusmods.com/grimrock/mods ... D422&pUp=1