Why can’t I increase side 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
Marcgal

Why can’t I increase side income?

Post by Marcgal »

Can someone enlightnen me why doesn’t this work?

Code: Select all

#define INCREASE_INCOME SIDE AMOUNT
    [store_side]
        side={SIDE}
        variable=_increase_income_stored_side
    [/store_side]
       
    [modify_side]
        side={SIDE}
        income="$_increase_income_stored_side.income+{AMOUNT}"
    [/modify_side]
#enddef
The intend is, hopefully, fairly obvious: side {SIDE} should have its base income increased by {AMOUNT}.

However, the effects I get are far from intended…

Assume side 2 has set income=0. Then $_increase_income_stored_side.income holds value of 2 (I presume this is because of the global base income?) But after calling {INCREASE INCOME 2 20} side 2 has base income of… 4. And I’d like it to be 22.

What am I doing wrong?
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Why can’t I increase side income?

Post by zookeeper »

There is no + syntax like that. You can do it in two ways:

The traditional way to do arithmetic in WML:

Code: Select all

#define INCREASE_INCOME SIDE AMOUNT
    [store_side]
        side={SIDE}
        variable=_increase_income_stored_side
    [/store_side]

    [set_variable]
        name=_increase_income_stored_side.income
        add={AMOUNT}
    [/set_variable]
       
    [modify_side]
        side={SIDE}
        income=$_increase_income_stored_side.income
    [/modify_side]
#enddef
And using a formula:

Code: Select all

#define INCREASE_INCOME SIDE AMOUNT
    [store_side]
        side={SIDE}
        variable=_increase_income_stored_side
    [/store_side]
       
    [modify_side]
        side={SIDE}
        income="$($_increase_income_stored_side.income + {AMOUNT})"
    [/modify_side]
#enddef
Post Reply