[Solved] Accessing [store_gold], etc, directly
Moderator: Forum Moderators
-
- Posts: 960
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
[Solved] Accessing [store_gold], etc, directly
Hoping this is a dumb question...
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
Code: Select all
wml.fire("store_gold",{variable="trader_menu_gold"}) -- ugly, fix me
local gold=wml.variables["trader_menu_gold"]
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.
Re: Accessing [store_gold], etc, directly
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 wayScenario 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.
-
- Posts: 960
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: Accessing [store_gold], etc, directly
Works great, thanks. And thanks for the link as well.
Speak softly, and carry Doombringer.
Re: [Solved] Accessing [store_gold], etc, directly
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}))
-
- Posts: 960
- Joined: August 26th, 2018, 11:46 pm
- Location: A country place, far outside the Wire
Re: [Solved] Accessing [store_gold], etc, directly
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.
- Pentarctagon
- Project Manager
- Posts: 5380
- Joined: March 22nd, 2009, 10:50 pm
- Location: Earth (occasionally)
Re: [Solved] Accessing [store_gold], etc, directly
$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
take one down, patch it around
-2,147,483,648 little bugs in the code
Re: [Solved] Accessing [store_gold], etc, directly
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.
Re: [Solved] Accessing [store_gold], etc, directly
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.
- Celtic_Minstrel
- Developer
- Posts: 2090
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: [Solved] Accessing [store_gold], etc, directly
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
.