This is similar to another thread where I was pointed to [insert_tag], which may be an alternative here, but I'd like to understand some things. I want to create an object in lua and feed that to [modify_unit]. I can create an object, and I can use [modify_unit] to add an object to a unit, but I can't seem to glue them together.
There's probably multiple things wrong here, but I've reduced it as simply as I can.
Here's what I'm trying:
I can see that the [lua] creates the object that I want, or at least something very close. But when I run the above, I get only one chat/print (from outside the [modify_unit] as shown below), and my unit has no [object].
I've noticed that it seems I can't do much inside [modify_unit]. For example, I have tried an failed to print/save the value of $this_unit in various ways, but whatever I try seems to be silently ignored. Can I use [lua] there? Is there a list of places where [lua] is acceptable? Is there a list of what I can/can't do inside [modify_unit] (I suppose "anything it doesn't say explicitly")?
I'm not convinced using 'return [object] ... [/object]' is valid. I'd hope so. I know I can do something like [if] [lua] return true|false[/lua] [/if]
I realize that because I'm using random I won't necessarily get the same object from the two [lua] blocks, but I believe this shows that the block returns roughly the data I want it to. Nothing follow this:
There's probably multiple things wrong here, but I've reduced it as simply as I can.
Here's what I'm trying:
Code:
[event] name=prerecruit id=fire wraith first_time_only=no [filter] side=3 type=Fire Wraith [/filter] [lua] code=<< local unit = wml.variables["unit"] local tmp = loti.item.type[1] -- ensure list is loaded local craftables = {} for i,item in pairs(loti.item.type) do if item.sort == "weaponword" then table.insert(craftables,i) end end local index = mathx.random(#craftables) local item = loti.item.type[craftables[index]] wesnoth.interface.add_chat_message(string.format("Outside modify_unit: %s will hold %s",unit.id,item.name)) print(wml.tostring({wml.tag.object(item)})) gui.show_lua_console() --return {wml.tag.object(item)} >> [/lua] [modify_unit] [filter] id=$unit.id [/filter] [lua] code=<< local unit = wml.variables["unit"] local tmp = loti.item.type[1] -- ensure list is loaded local craftables = {} for i,item in pairs(loti.item.type) do if item.sort == "weaponword" then table.insert(craftables,i) end end local index = mathx.random(#craftables) local item = loti.item.type[craftables[index]] wesnoth.interface.add_chat_message(string.format("%s will hold %s",unit.id,item.name)) print(wml.tostring({wml.tag.object(item)})) gui.show_lua_console() return {wml.tag.object(item)} >> [/lua] [/modify_unit] [/event]
I've noticed that it seems I can't do much inside [modify_unit]. For example, I have tried an failed to print/save the value of $this_unit in various ways, but whatever I try seems to be silently ignored. Can I use [lua] there? Is there a list of places where [lua] is acceptable? Is there a list of what I can/can't do inside [modify_unit] (I suppose "anything it doesn't say explicitly")?
I'm not convinced using 'return [object] ... [/object]' is valid. I'd hope so. I know I can do something like [if] [lua] return true|false[/lua] [/if]
I realize that because I'm using random I won't necessarily get the same object from the two [lua] blocks, but I believe this shows that the block returns roughly the data I want it to. Nothing follow this:
Code:
20240420 11:48:18 info scripting/lua: Script says: "Outside modify_unit: Fire Wraith-9524 will hold Gloombringer"20240420 11:48:18 debug scripting/lua: intf_print called:20240420 11:48:18 debug scripting/lua: '[object]amethysts=1attacks=30black_pearls=0damage=20description="<span color='green'>Damage increased by 20%</span><span color='green'>30% more attacks </span><span color='#60A0FF'>Resistance to pierce increased by 10%</span><span color='#C0C000'>New weapon special: poison</span><span color='#60A0FF'>Chance to get hit decreased by 10%</span><span color='#808080'><i>One side wins, the other side loses. Both sides' widows weep.</i></span>"diamonds=0dodge=10emeralds=4#textdomain wesnoth-lotiflavour=_"One side wins, the other side loses. Both sides' widows weep."image="items/leather-pack.png"name=_"Gloombringer"number=583obsidians=2opals=0pearls=0pierce_resist=10rubies=1sapphires=0sort="weaponword"topazes=1[specials][poison]#textdomain wesnoth-helpdescription=_"This attack poisons living targets. Poisoned units lose 8 HP every turn until they are cured or are reduced to 1 HP. Poison cannot, of itself, kill a unit."id="poison"name=_"poison"special_note=_"The victims of this unit’s poison will continually take damage until they can be cured in town or by a unit which cures."[/poison][/specials][/object]'
Statistics: Posted by white_haired_uncle — Yesterday, 5:24 pm