Modifying the Engine on Windows

All development conversation and discussion takes place here

Moderator: Moderator

Message
Author
yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: Modifying the Engine on Windows

#16 Post by yufra »

If I understand correctly, you want to change how the player character is displayed from the Lua console. I am vaguely familiar with this section of the code, and will try explaining it but if I go wrong hopefully DG will come to the rescue. The graphics are C objects and the Lua objects (player, actor, terrain, etc) carry around a reference to the graphics object so that the engine knows where to move that tile/character. You probably changed game.player.display, game.player.color_r, etc. to no avail. That is because those variables are only used to construct the graphics object, which is done on creation/loading, but if the Lua object already has a reference to the graphics objects these variables are essentially ignored. You can force the entity to regenerate its graphics objects from the Lua properties using this code right after you modify the Lua object, though:

Code: Select all

        if self._mo then
                self._mo:invalidate()
                game.level.map:updateMap(self.x, self.y)
        end
This code checks if we have a graphics object (stored in Entity._mo) and if we do it invalidates it, forcing it to be recreated the next time the map is updated which we cause to happen right now. Cheers!
<DarkGod> lets say it's intended

Graziel
Wyrmic
Posts: 234
Joined: Wed Sep 15, 2010 10:32 am

Re: Modifying the Engine on Windows

#17 Post by Graziel »

That worked, thanks!
You are likely to be eaten by a grue

Graziel
Wyrmic
Posts: 234
Joined: Wed Sep 15, 2010 10:32 am

Re: Modifying the Engine on Windows

#18 Post by Graziel »

I need help with another one,

I need to move all equipment from 1 entity to other, i got already to :

Code: Select all

self.body = target.body
self.inven = target.inven
self.inven_def = target.inven_def
as much as it works on one way (body -> tmp,target -> body) the other way it doesnt (body -> target, tmp-> body) i get :

Code: Select all

Lua Error: /engine/dialogs/ShowEquipInven.lua:181: bad argument #1 to 'ipairs' (table expected, got nil)
	At [C]:-1 
	At [C]:-1 ipairs
	At /engine/dialogs/ShowEquipInven.lua:181 generateList
	At /engine/dialogs/ShowEquipInven.lua:35 init
	At /engine/class.lua:64 new
	At /engine/interface/ActorInventory.lua:220 showEquipInven
	At /mod/class/Game.lua:739 ?
	At /engine/KeyBind.lua:202 
You are likely to be eaten by a grue

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: Modifying the Engine on Windows

#19 Post by yufra »

Graziel wrote: I need to move all equipment from 1 entity to other, i got already to :

Code: Select all

self.body = target.body
self.inven = target.inven
self.inven_def = target.inven_def
Ignoring any nuances of if the body table are compatible between the two actors, you can achieve a swap with the following code:

Code: Select all

self.body, target.body = target.body, self.body
self.inven, target.inven = target.inven, self.inven
self.inven_def, target.inven_def = target.inven_def, self.inven_def
Does that do what you want?
<DarkGod> lets say it's intended

Graziel
Wyrmic
Posts: 234
Joined: Wed Sep 15, 2010 10:32 am

Re: Modifying the Engine on Windows

#20 Post by Graziel »

Well somehow it helped, at least it gave me a hint i looked at good variables : )
The thing was i killed Tmp actor before transferring items thats why it failed.

Anyway thanks, again ; )
You are likely to be eaten by a grue

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Modifying the Engine on Windows

#21 Post by darkgod »

BEware, this looks like it works it it does not really, the items will indeed be transfered but not the properties.
If say one of the items provided +2 lite then the new actor will not get it.
You must iterate over all items, remove them (usign actor:removeObject()) and add them to the new one (using actor:addObject())
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Graziel
Wyrmic
Posts: 234
Joined: Wed Sep 15, 2010 10:32 am

Re: Modifying the Engine on Windows

#22 Post by Graziel »

how do i iterate throu all of them? i have already tried few things but non of them give me desired effect

Code: Select all

self.body = target.body
		local to, from = self.inven, target.inven --self:getInven("INVEN"), target:getInven("INVEN")
		for inven_id =  1, #target.inven_def do			
			for item, o in ipairs(target.inven[inven_id]) do
				local o = target:removeObject(from, item)
				self:addObject(to, o)
			end
		end
gives me:

Code: Select all

/engine/interface/ActorInventory.lua:155: in function 'removeObject'
if i remove comment:

Code: Select all

/engine/interface/ActorInventory.lua:90: in function 'addObject'
You are likely to be eaten by a grue

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Modifying the Engine on Windows

#23 Post by darkgod »

Untested but something like that:

Code: Select all

for inven_id, inven in pairs(src.inven) do
	for i = #inven, 1, -1 do
		local o = src:removeObject(inven, i, true)
		dest:addObject(inven_id, o)
	end
end
This iterated over all inventories of the src, then over all items of each inventory (in reverse order because we are removing items). It removes the object from the src and adds it to dest.
Obviously dest needs to have a correctly defined body with the correct body slots
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Graziel
Wyrmic
Posts: 234
Joined: Wed Sep 15, 2010 10:32 am

Re: Modifying the Engine on Windows

#24 Post by Graziel »

nuuu it still gives me:

Code: Select all

/engine/interface/ActorInventory.lua:90: in function 'addObject'
it looks like :

Code: Select all

self.body = target.body
doesnt transfer body slots as i thought : P
You are likely to be eaten by a grue

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Modifying the Engine on Windows

#25 Post by darkgod »

No it does not, body is only used during entity initialisation.
You need to have the destination actor have a correct body from birth, you cant ?

If not then you can probably do something like that: (but it's ugly ;> )

Code: Select all

dest.inven = {}
for inven_id, inven in pairs(src.inven) do
	local tmp = {}
	for i = #inven, 1, -1 do
		local o = src:removeObject(inven, i, true)
		tmp[#tmp+1] = o
	end
	dest.inven[inven_id] = table.copy(inven, true)
	for i = 1, #tmp do dest:addObject(inven_id, tmp[i]) end
	desc:sortInven(inven_id)
end
(again untested)
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Graziel
Wyrmic
Posts: 234
Joined: Wed Sep 15, 2010 10:32 am

Re: Modifying the Engine on Windows

#26 Post by Graziel »

Code: Select all

self.inven = {}
		for inven_id, inven in pairs(target.inven) do
			local tmp = {}
			for i = #inven, 1, -1 do
			  local o = target:removeObject(inven, i, true)
			  tmp[#tmp+1] = o
			end
			self.inven[inven_id] = table:copy(inven, true)
			for i = 1, #tmp do 
				self:addObject(inven_id, tmp[i]) 
			end
			self:sortInven(inven_id)
		end

Code: Select all

self.inven[inven_id] = table:copy(inven, true)
gives - i tried with .(dot) also -

Code: Select all

attempt to call field 'copy' (a nil value)
You are likely to be eaten by a grue

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Modifying the Engine on Windows

#27 Post by darkgod »

See, told you it was untested ! :)
Obviously it's table.clone and not table:clone ;>
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Graziel
Wyrmic
Posts: 234
Joined: Wed Sep 15, 2010 10:32 am

Re: Modifying the Engine on Windows

#28 Post by Graziel »

And DG saves the day again!
You are likely to be eaten by a grue

Lord Leks Darkmind
Yeek
Posts: 13
Joined: Sat Mar 09, 2013 1:03 am

Re: Modifying the Engine on Windows

#29 Post by Lord Leks Darkmind »

um.. sorry, possibly wrong thread... english ain`t good, no programming skills at all.
so: created item

Code: Select all

newEntity{ base = "BASE_RING",
	name = "Titan powered ring",
	power_source = {arcane=true},
	unique = true,
	color = colors.UMBER,
	image="object/artifact/ring_vargh_redemption.png",
	unided_name = "strange ring",
	desc = [[uneasy feeling emanates from this ring.]],
	level_range = {0, 90},
	greater_ego = 1,
	rarity = 220,
	cost = 999990,
... but can`t test it, coz can`t add it to char inventory... so - problem: how to add sertain item to inventory through talent or birth (difficulty settings).

later edit:
through birth descriptors:

Code: Select all

resolvers.inventory{ id=true, {type="jewelry", subtype="ring", ingore_material_restriction=true, name="Titan powered ring", ego_chance=1000}, },
but still cant find away to add item through talent use.

Post Reply