Issues with coding

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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
LordAwsomeness
Posts: 96
Joined: August 12th, 2013, 2:20 pm
Location: U.S.A.

Issues with coding

Post by LordAwsomeness » November 20th, 2018, 7:34 pm

Hi! So I am having some issues with the following code. Essentially the code is part of the player hero creation, and some new code I was just adding in is supposed to automatically equip the weapons you are handed. The following code works:

Code: Select all

#define LA_SET_HERO_CLASS_OPTION4 IMAGE CLASS_DESCRIPTION CLASS DESCRIPTION RACE WEAPON1 WEAPON2 TRAIT RANGE TYPE VARIATION2 RANGE2 TYPE2
{LA_OPTION_IMAGE_SHOW_IF "units/$la_hero[$side_number].race/{IMAGE}.png" "<span color='#00FF00' weight='bold'>{CLASS_DESCRIPTION}</span>
<span size='x-small'>{DESCRIPTION}</span>
<span color='#FF8000' size='xx-small'>PRIMARY: $la_weapons.{WEAPON1}_2.name
SECONDARY: $la_weapons.{WEAPON2}_1.name</span>" ({VARIABLE_CONDITIONAL la_hero[$side_number].race equals {RACE}}) (
[modify_unit]
[filter]
side=$side_number
[/filter]
side=$side_number
canrecruit=yes
[modifications]
{TRAIT}
[/modifications]
[/modify_unit]
{VARIABLE la_inventory[$side_number].potion.red_small 3}
{VARIABLE la_inventory[$side_number].potion.red_medium 1}
{VARIABLE la_inventory[$side_number].potion_blue_tiny 1}
{VARIABLE la_inventory[$side_number].{WEAPON1}_2 1}
{VARIABLE la_inventory[$side_number].{WEAPON2}_1 1}

{VARIABLE la_hero[$side_number].class_description "{CLASS_DESCRIPTION}"}
{VARIABLE la_hero[$side_number].class {CLASS}}

#VARIATION VARIATION2 RANGE RANGE2 TYPE TYPE2

{LA_WEAPON_MATH {WEAPON1}_2 $la_weapons.{WEAPON1}_2.skill1 la_weapons.{WEAPON1}_2.skill2}
{VARIABLE la_inventory[$side_number].equipped_{RANGE} {WEAPON1}_2}
{LA_EQUIP_ITEM {IMAGE} ($la_weapons.{WEAPON1}_2.name) ($la_weapons.{WEAPON1}_2.image) {TYPE} {RANGE} $la_weapons[$side_number].{WEAPON1}_2.damage $la_weapons[$side_number].{WEAPON1}_2.strikes {IMAGE}}

{LA_WEAPON_MATH {WEAPON2}_1 $la_weapons.{WEAPON2}_1.skill1 la_weapons.{WEAPON2}_1.skill2}
{VARIABLE la_inventory[$side_number].equipped_{RANGE2} {WEAPON2}_1}
{LA_EQUIP_ITEM {VARIATION2} ($la_weapons.{WEAPON2}_1.name) ($la_weapons.{WEAPON2}_1.image) {TYPE2} {RANGE2} $la_weapons[$side_number].{WEAPON2}_1.damage $la_weapons[$side_number].{WEAPON2}_1.strikes {IMAGE}}
)}
#enddef[/c]

Now this is what the macro actually looks like in  action:
[c]{LA_SET_HERO_CLASS_OPTION4 "axe" "Warrior (BRUISER)" bruiser "Years of service in the dwarfish armies gave you the experience you need to wield your axe and mace. You prefer melee weapons to ranged, and prefer combat over words." dwarf axe mace {LA_CLASS_BRUISER} melee blade mace melee impact}
The following one is a slightly adapted version of the previous code; essentially the following code is identical except it only has one weapon to equip and assign to the hero instead of the standard 2 weapons. so in theory since nothing is really changed, it should automatically work.

Code: Select all

#define LA_SET_HERO_CLASS_OPTION2 IMAGE CLASS_DESCRIPTION CLASS DESCRIPTION RACE WEAPON1 WEAPON2 TRAIT RANGE TYPE
{LA_OPTION_IMAGE_SHOW_IF "units/$la_hero[$side_number].race/{IMAGE}.png" "<span color='#00FF00' weight='bold'>{CLASS_DESCRIPTION}</span>
<span size='x-small'>{DESCRIPTION}</span>
<span color='#FF8000' size='xx-small'>PRIMARY: $la_weapons.{WEAPON1}_3.name
SECONDARY: {WEAPON2}</span>" ({VARIABLE_CONDITIONAL la_hero[$side_number].race equals {RACE}}) (
[modify_unit]
[filter]
side=$side_number
[/filter]
side=$side_number
canrecruit=yes
[modifications]
{TRAIT}
[/modifications]
[/modify_unit]
{VARIABLE la_inventory[$side_number].potion.red_small 3}
{VARIABLE la_inventory[$side_number].potion.red_medium 1}
{VARIABLE la_inventory[$side_number].potion_blue_tiny 1}
{VARIABLE la_inventory[$side_number].{WEAPON1}_3 1}
{VARIABLE la_hero[$side_number].class_description "{CLASS_DESCRIPTION}"}
{VARIABLE la_hero[$side_number].class {CLASS}})}


{LA_WEAPON_MATH {WEAPON1}_3 $la_weapons.{WEAPON1}_3.skill1 la_weapons.{WEAPON1}_3.skill2}
{VARIABLE la_inventory[$side_number].equipped_{RANGE} {WEAPON1}_3}
{LA_EQUIP_ITEM {IMAGE} ($la_weapons.{WEAPON1}_3.name) ($la_weapons.{WEAPON1}_3.image) {TYPE} {RANGE} $la_weapons[$side_number].{WEAPON1}_3.damage $la_weapons[$side_number].{WEAPON1}_3.strikes {IMAGE}}
#enddef
Finally here is the adapted version's macro in action:

Code: Select all

{LA_SET_HERO_CLASS_OPTION2 "mace" "Warrior (FIGHTER)" fighter "warrior desc" troll hammer none {LA_CLASS_FIGHTER} melee impact}
There are not any loading issues with the code; essentially everything works still except for the macro does not automatically equip the weapons like it should. the variables still fire and the player can still manually assign their weapons, however for better quality of life solutions I wanted to automatically equip the weapons for the players upon choosing their class. If you find something that I am doing wrong feel free to correct me! Thank oyu!
Last edited by shadowm on November 20th, 2018, 9:34 pm, edited 1 time in total.
Reason: Replaced [c] with [code]
- Been playing Wesnoth since 2004 and the 1.0.x versions.
- Creator of Undead Invasion MP Scenario Pack.
- Creator of Valeria MP Adventure

Post Reply