why can not change income

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
ERROR1025
Posts: 46
Joined: February 23rd, 2020, 10:18 am

why can not change income

Post by ERROR1025 »

Code: Select all

[event]
	name=start
	first_time_only=yes
		[lua]
			code = <<
				side1.base_income = side1.base_income + {S1G}
			>>
		[/lua]
[/event]
the WML can not work,i hope "side 1 turn gold +{S1G}"
S1G is variable
Last edited by WhiteWolf on February 5th, 2023, 8:09 am, edited 1 time in total.
Reason: [code]
User avatar
Helmet
Posts: 641
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: why can not change income

Post by Helmet »

Base income and income are two different things. I don't use lua for changing income. I do this:

Code: Select all

    [side]
		side=1
		gold=150
		income=3 #            bonus added to base income 2
		village_gold=2 #      default=1	
		...etc.
    [/side]
I'm not sure if this helps. Good luck.
Author of:
DIY Campaign, Confederacy of Swamp Creatures: Big Battle 1, Confederacy of Swamp Creatures: Big Battle 2, Frogfolk Delivery Service, The Pool of Ek.
User avatar
ERROR1025
Posts: 46
Joined: February 23rd, 2020, 10:18 am

Re: why can not change income

Post by ERROR1025 »

i need it work on other map or cfg,not have help
User avatar
Ravana
Forum Moderator
Posts: 3000
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: why can not change income

Post by Ravana »

Even if S1G is variable, {S1G} is table. Adding table to income does not do anything useful.

Are you sure you want to use Lua?
User avatar
ERROR1025
Posts: 46
Joined: February 23rd, 2020, 10:18 am

Re: why can not change income

Post by ERROR1025 »

I didn't find a way to modify "turn/gold" in WML, I think only LUA can do it
User avatar
Lord-Knightmare
Discord Moderator
Posts: 2359
Joined: May 24th, 2010, 5:26 pm
Location: Somewhere in the depths of Irdya, gathering my army to eventually destroy the known world.
Contact:

Re: why can not change income

Post by Lord-Knightmare »

Code: Select all

[event]
name="turn 2"
    [modify_side]
        income=12
        gold=50
    [/modify_side]
[/event]
Creator of "War of Legends"
Creator of the Isle of Mists survival scenario.
Maintainer of Forward They Cried
User:Knyghtmare | My Medium
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: why can not change income

Post by Celtic_Minstrel »

Even if you wanted to do that in Lua, you're doing it wrong. There is no such variable as side1. Also, it looks like you're trying to substitute in a macro with {S1G}, but the Lua code is wrapped in `<< >>` which prevents macro substitution.

If for some reason Lord-Knightmare's suggestion doesn't do what you want, you could try this:

Code: Select all

[event]
	name=start
	first_time_only=yes
	[lua]
		code = "
			wesnoth.sides[1].base_income = wesnoth.sides[1].base_income + {S1G}
		"
	[/lua]
[/event]
Although, substituting macros directly into Lua code is generally not a good idea, so it would be better to write it like this:

Code: Select all

[event]
	name=start
	first_time_only=yes
	[lua]
		code = <<
			local args = ... # this line just lets you use anything from the [args] tag in your code
			wesnoth.sides[1].base_income = wesnoth.sides[1].base_income + args.add
		>>
		[args]
			add={S1G}
		[/args]
	[/lua]
[/event]
On the other hand, you mentioned that S1G is a variable. I'd assumed you were misusing terminology and it was actually a macro. However, if I'm wrong and it really is a WML variable, then you would have to write it like this instead:

Code: Select all

[event]
	name=start
	first_time_only=yes
	[lua]
		code = <<
			wesnoth.sides[1].base_income = wesnoth.sides[1].base_income + wml.variables["S1G"]
		>>
	[/lua]
[/event]
And if it's a Lua variable, which I assume is unlikely but is not impossible if you had other Lua code somewhere that assigns it as a global variable, then you would need to write your code like this:

Code: Select all

[event]
	name=start
	first_time_only=yes
	[lua]
		code = <<
			wesnoth.sides[1].base_income = wesnoth.sides[1].base_income + S1G
		>>
	[/lua]
[/event]
But there's no need to do any of this if [modify_side] does what you need.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply