[Solved] Accessing [store_gold], etc, directly

Discussion of Lua and LuaWML support, development, and ideas.

Moderator: Forum Moderators

Post Reply
white_haired_uncle
Posts: 1205
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

[Solved] Accessing [store_gold], etc, directly

Post by white_haired_uncle »

Hoping this is a dumb question...

Code: Select all

wml.fire("store_gold",{variable="trader_menu_gold"})  -- ugly, fix me
local gold=wml.variables["trader_menu_gold"]
This works, but it means using a wml variable with no guarantee it's not clobbering something existing.

I've seen another way of calling events (not wml.fire), don't have an example right now unfortunately, but I never could get the syntax right.


P.S. Is there any way to get this search engine (or any other on earth) to search for something like "store_gold"? Everything I've tried searches for "store" (splitting store_gold into "store" and "gold" and then ignoring gold because it's too common, even though that's NOT what I asked for).

TIA
Last edited by white_haired_uncle on July 21st, 2023, 12:32 pm, edited 1 time in total.
Speak softly, and carry Doombringer.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: Accessing [store_gold], etc, directly

Post by gfgtdf »

I didn't test it, but you should be able to write local gold = wesnoth.sides.get(1).gold. Here https://wiki.wesnoth.org/LuaAPI/types/side you cen see which other attributes can be read that way
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
white_haired_uncle
Posts: 1205
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: Accessing [store_gold], etc, directly

Post by white_haired_uncle »

Works great, thanks. And thanks for the link as well.
Speak softly, and carry Doombringer.
User avatar
Ravana
Forum Moderator
Posts: 3014
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [Solved] Accessing [store_gold], etc, directly

Post by Ravana »

Example to show the other syntax

Code: Select all

wml.variables.x = "abc"

wesnoth.wml_actions.message{message="$x"}

wml.fire("message", {message="$x"})
wesnoth.wml_actions.message(wml.tovconfig{message="$x"})
wesnoth.wml_actions.message(wml.interpolate({message="$x"}, wml.all_variables))
wesnoth.wml_actions.message(wml.interpolate({message="$x"}, {x = wml.variables.x}))
white_haired_uncle
Posts: 1205
Joined: August 26th, 2018, 11:46 pm
Location: A country place, far outside the Wire

Re: [Solved] Accessing [store_gold], etc, directly

Post by white_haired_uncle »

I couldn't find a way I liked to get the current side. Since I was more or less in a moveto event, I knew I could use a specific unit, but I'm less than thrilled with this.

Code: Select all

local side_number = wesnoth.sides.find{ wml.tag.has_unit { x=cfg.x,y=cfg.y }}[1].side
Speak softly, and carry Doombringer.
User avatar
Pentarctagon
Project Manager
Posts: 5566
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: [Solved] Accessing [store_gold], etc, directly

Post by Pentarctagon »

$side_number?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Ravana
Forum Moderator
Posts: 3014
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: [Solved] Accessing [store_gold], etc, directly

Post by Ravana »

As Lua, wml.variables.side_number. There is also something like wesnoth.current.side, but I dont remember if that is what you are supposed to use as LuaAPI.
gfgtdf
Developer
Posts: 1432
Joined: February 10th, 2013, 2:25 pm

Re: [Solved] Accessing [store_gold], etc, directly

Post by gfgtdf »

Ravana wrote: July 23rd, 2023, 8:57 am As Lua, wml.variables.side_number. There is also something like wesnoth.current.side, but I dont remember if that is what you are supposed to use as LuaAPI.
You can certainly use it, (Its documented in https://wiki.wesnoth.org/LuaAPI/wesnoth#wesnoth.current and commonly used in mainline, for example in World conquest). so the code would looks like wesnoth.sides[wesnoth.current.side].gold or wesnoth.sides.get(wesnoth.current.side).gold
Scenario with Robots SP scenario (1.11/1.12), allows you to build your units with components, PYR No preperation turn 1.12 mp-mod that allows you to select your units immideately after the game begins.
User avatar
Celtic_Minstrel
Developer
Posts: 2235
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: [Solved] Accessing [store_gold], etc, directly

Post by Celtic_Minstrel »

wesnoth.current.side returns the current active side, which is probably what you want, but if you actually wanted the side of the unit involved where it might not be on the active side, you could also use wesnoth.variables.unit.side or wesnoth.variables.second_unit.side.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply