To summarize the if[] effect[] bracket behavior is inconsistent depending on the level of the nesting.
not really sure how to make this simplerGood catch. Could you create and test a very simple example for a bug report?
I can do it later this week if you don't find the time.
Expected behavior:
1). mutual exclusion.
When a condition is met the other conditions within the scope of the else statements following or preceding each other are not executed such as, case c and case d in the same turn
2). non repeated execution
The same code will not execute twice in the same turn such as case D twice or case A D in the same turn (sometimes).
Code: Select all
Tech
name = "DEF_PLANET_GUN"
description = "DEF_PLANET_GUN_DESC"
short_description = "DEFENSE_SHORT_DESC"
category = "DEFENSE_CATEGORY"
researchcost = 10
researchturns = 1
prerequisites = "DEF_ROOT_DEFENSE"
unlock = Item type = Building name = "BLD_PLANETARY_GUN"
graphic = "icons/tech/defense.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"
Code: Select all
BLD_PLANETARY_GUN
Planetary Gun Building
BLD_PLANETARY_GUN_DESC
'''planetary defense gun building description.'''
DEF_PLANET_GUN
Planetary Gun
DEF_PLANET_GUN_DESC
'''planetary gun description''
Code: Select all
EFFECT_TESTCASE_LABEL
effect_if_else testcase label
EFFECT_TESTCASE_A
case A
EFFECT_TESTCASE_B
case B
EFFECT_TESTCASE_C
case C
EFFECT_TESTCASE_D
case D
Code: Select all
BuildingType
name = "BLD_PLANETARY_GUN"
description = "BLD_PLANETARY_GUN_DESC"
buildcost = 10
buildtime = 1
location = And [
Planet
Not Contains Building name = "BLD_PLANETARY_GUN"
Not Planet type = [GasGiant]
OwnedBy empire = Source.Owner
]
EnqueueLocation = And [
Not Contains Building name = "BLD_PLANETARY_GUN"
Not Enqueued type = Building name = "BLD_PLANETARY_GUN"
Not Planet type = [GasGiant]
OwnedBy empire = Source.Owner
]
effectsgroups = [
EffectsGroup
scope = NumberOf number = 1 condition = And [
Ship
InSystem id = Source.SystemID
Or [
OwnedBy affiliation = EnemyOf empire = Source.Owner
Unowned
]
//VisibleToEmpire empire = Source.Owner
]
activation = Source
effects =
[
If condition = and [
Not VisibleToEmpire empire = Source.Owner
Structure high = 15
]
effects =
[
GenerateSitrepMessage
message = "EFFECT_TESTCASE_A"
label = "EFFECT_TESTCASE_LABEL"
icon = "icons/sitrep/combat_destroyed.png"
]
else =
If condition = and [
Not VisibleToEmpire empire = Source.Owner
Structure low = 15
]
effects =
[
GenerateSitrepMessage
message = "EFFECT_TESTCASE_B"
label = "EFFECT_TESTCASE_LABEL"
icon = "icons/sitrep/combat_destroyed.png"
]
else =
If condition = and [
VisibleToEmpire empire = Source.Owner
Structure high = 15
]
effects =
[
GenerateSitrepMessage
message = "EFFECT_TESTCASE_C"
label = "EFFECT_TESTCASE_LABEL"
icon = "icons/sitrep/combat_destroyed.png"
]
else =
If condition = and [
VisibleToEmpire empire = Source.Owner
Structure low = 15
]
effects =
[
GenerateSitrepMessage
message = "EFFECT_TESTCASE_D"
label = "EFFECT_TESTCASE_LABEL"
icon = "icons/sitrep/combat_destroyed.png"
]
]
]
icon = "icons/meter/damage.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"
Nor any duel combination just one of them per turn.
Or if you like simply replace that above with the below.
It still messes up chained else if's statements don't work right either.
Visibility makes no difference as shown below and above same messed up results.
Code: Select all
BuildingType
name = "BLD_PLANETARY_GUN"
description = "BLD_PLANETARY_GUN_DESC"
buildcost = 10
buildtime = 1
location = And [
Planet
Not Contains Building name = "BLD_PLANETARY_GUN"
Not Planet type = [GasGiant]
OwnedBy empire = Source.Owner
]
EnqueueLocation = And [
Not Contains Building name = "BLD_PLANETARY_GUN"
Not Enqueued type = Building name = "BLD_PLANETARY_GUN"
Not Planet type = [GasGiant]
OwnedBy empire = Source.Owner
]
effectsgroups = [
EffectsGroup
scope = NumberOf number = 1 condition = And [
Ship
InSystem id = Source.SystemID
Or [
OwnedBy affiliation = EnemyOf empire = Source.Owner
Unowned
]
VisibleToEmpire empire = Source.Owner
]
activation = Source
effects =
[
//#0
If condition = and [
Structure high = 8
]
effects =
[
GenerateSitrepMessage
message = "EFFECT_TESTCASE_A"
label = "EFFECT_TESTCASE_LABEL"
icon = "icons/sitrep/combat_destroyed.png"
]
//#1
else =
If condition = and [
Structure high = 15
]
effects =
[
GenerateSitrepMessage
message = "EFFECT_TESTCASE_B"
label = "EFFECT_TESTCASE_LABEL"
icon = "icons/sitrep/combat_destroyed.png"
]
//#2
else =
If condition = and [
Structure high = 30
]
effects =
[
GenerateSitrepMessage
message = "EFFECT_TESTCASE_C"
label = "EFFECT_TESTCASE_LABEL"
icon = "icons/sitrep/combat_destroyed.png"
]
//#3
else =
If condition = and [
Structure high = 100
]
effects =
[
GenerateSitrepMessage
message = "EFFECT_TESTCASE_D"
label = "EFFECT_TESTCASE_LABEL"
icon = "icons/sitrep/combat_destroyed.png"
]
// end
]
]
icon = "icons/meter/damage.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"
Honestly id be happy with just like 2 or 3 levels of ifs even hard coded if it worked right, i don't really need it to be true recursive nesting.
Else if and nested if's complicates it a bit due to parsing and rules i suppose that's gotta be tough to parse.
Some kind of switch case might have been easier were i added matching conditions to a int flag to do a switch case on. Something like the below binary selection.
flag a Value = value + if[ VisibleToEmpire empire = Source.Owner ] * 1
flag a Value = value + if[ Structure low = 15 ] * 2
flag a Value = value + if[ Fuel low = 1 ] * 4
switch[ flag a ]
[
effect[...] // 0
effect[...] // 1
effect[...] // 2
effect[...] // 3
effect[...] // 4
effect[...] // 5
effect[...] // 6
effect[...] // 7
]
Were switch just holds a list/array of effects and the flag has one number to pick one that can execute that's basically the 'same' as a chain of, if else if or even groups of nested chains of them. Id take that alternatively