Scripting Questions In General

Creation, discussion, and balancing of game content such as techs, buildings, ship parts.

Moderators: Oberlus, Committer

Message
Author
xlightwavex
Space Kraken
Posts: 111
Joined: Mon Nov 16, 2015 5:57 am

Re: Scripting Questions In General

#31 Post by xlightwavex »

Geoff the Medio wrote:Hmm. I suspect that there's some code that is set up to only execute SetMeter effects but isn't recognizing that the If effect might contain SetMeter effects, so is skipping over them when updating meters.
You know worse yet i tried and tried to get number of to work in sequence with activation to no avail. kept getting script errors or it just failed to work at all, otherwise maybe i could work around it in that way but.

Humm well im stumped ?
Last edited by xlightwavex on Mon Sep 26, 2016 12:23 pm, edited 1 time in total.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Scripting Questions In General

#32 Post by Geoff the Medio »

To clarify, it's not an issue with your script; it's an issue with the code that executes your script.

For now, you probably can't use If/else effects with SetMeter in them. Hopefully I can fix it soon, though.

xlightwavex
Space Kraken
Posts: 111
Joined: Mon Nov 16, 2015 5:57 am

Re: Scripting Questions In General

#33 Post by xlightwavex »

Geoff the Medio wrote:To clarify, it's not an issue with your script; it's an issue with the code that executes your script.

For now, you probably can't use If/else effects with SetMeter in them. Hopefully I can fix it soon, though.
Is there a example for SetMeter ?.

I have a partial solution but i would have to drop being able to fire on cloaks with a 1 in 4 chance to hit completely. That is just to have the messages in if else and destroy in one or the other and always do damage.

Well the next attempt may have to wait for a bit but ill try it.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Scripting Questions In General

#34 Post by Geoff the Medio »

xlightwavex wrote:Is there a example for SetMeter ?
Probably in mines techs.
That is just to have the messages in if else and destroy in one or the other and always do damage.
You only really need the GenerateSitrep and Destroy effects in the If/else effect; you could just have the SetMeter effect always execute (not with an If effect), and then also destroy the ship and generate the destroy message if its structure is low enough, and just generate a damaged sitrep if its structure is high enough.

xlightwavex
Space Kraken
Posts: 111
Joined: Mon Nov 16, 2015 5:57 am

Re: Scripting Questions In General

#35 Post by xlightwavex »

Geoff the Medio wrote:
xlightwavex wrote:Is there a example for SetMeter ?
Probably in mines techs.
That is just to have the messages in if else and destroy in one or the other and always do damage.
You only really need the GenerateSitrep and Destroy effects in the If/else effect; you could just have the SetMeter effect always execute (not with an If effect), and then also destroy the ship and generate the destroy message if its structure is low enough, and just generate a damaged sitrep if its structure is high enough.
Ah sorry i misread what you said, i saw cant as can lol. I thought you were referring to SetMeter as a different way to achieve it like it was a separate keyword, i see though.

Yes i can get a partial resolution for the moment but it is a bit disappointing. Have you taken a look to see how hard of a fix that is ?
Last edited by xlightwavex on Mon Sep 26, 2016 9:59 pm, edited 1 time in total.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Scripting Questions In General

#36 Post by Geoff the Medio »

Until people start actually using scriptable functions, issues such as this don't pop up. Fixing it isn't trivial, either.

xlightwavex
Space Kraken
Posts: 111
Joined: Mon Nov 16, 2015 5:57 am

Re: Scripting Questions In General

#37 Post by xlightwavex »

Geoff the Medio wrote:Fixing it isn't trivial, either.
Ackkkkk !!!!

Well it looks like my first contribution to fo is in giving you a headache/bug to solve. :)

New question how do planetary shields work vs bombardment or to stop damage ?


Here is the temporary version for now.
The tech remains the same as displayed in the very first post.
As well as the full code that should work but cant due to the bug.

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
        OwnedBy affiliation = EnemyOf empire = Source.Owner         
    ]
    //
    // Non cloaked ships
    // 
    effects = 
    [
        
        SetStructure value = Value -((CurrentTurn / 14 + Target.MaxStructure / 6) +4 - Target.Shield)
        SetFuel value = Value -(.5+ Target.MaxFuel / 5)  
        
        If condition = and 
        [
            Structure high = ((CurrentTurn / 14 + Target.MaxStructure / 6) +4 - Target.Shield)
            VisibleToEmpire empire = Source.Owner  
        ]
        effects = 
        [
            Destroy
             //
            // msg to the player firing the gun
            GenerateSitrepMessage
                message = "EFFECT_PLANETARY_GUN_HIT_DESTROYED"
                label = "EFFECT_PLANETARY_GUN_LABEL"
                icon = "icons/sitrep/combat_destroyed.png"
                parameters = 
                [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "source" data = Source.Owner
                    tag = "target" data = Target.Owner
                    tag = "ship" data = Target.ID
                ]
                empire = Source.Owner
             //
            // msg to the player hit destroyed
            GenerateSitrepMessage
                message = "EFFECT_PLANETARY_GUN_DESTROYED_ME"
                label = "EFFECT_PLANETARY_GUN_LABEL"
                icon = "icons/sitrep/combat_destroyed.png"
                parameters = 
                [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "ship" data = Target.ID
                ]
                empire = Target.Owner
        ]
        else = if condition = and
        [
            Structure low = ((CurrentTurn / 14 + Target.MaxStructure / 6) +4 - Target.Shield)
            VisibleToEmpire empire = Source.Owner  
        ]
        effects =
        [
            //SetStructure value = Value -((CurrentTurn / 14 + Target.MaxStructure / 6) +4 - Target.Shield)
            //SetFuel value = Value -(.5+ Target.MaxFuel / 5)  
             // 
            // msg to the player firing the gun
            GenerateSitrepMessage
                message = "EFFECT_PLANETARY_GUN_HIT"
                label = "EFFECT_PLANETARY_GUN_LABEL"
                icon = "icons/meter/damage.png"
                parameters = 
                [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "ship" data = Target.ID
                    tag = "rawtext" data = ((CurrentTurn / 14 + Target.MaxStructure / 6) +4 - Target.Shield)
                    tag = "source" data = Source.Owner
                    tag = "target" data = Target.Owner
                    //tag = "empire" data = Target.Owner
                ]
                empire = Source.Owner
             // 
            // msg to the player that was hit
            GenerateSitrepMessage
                message = "EFFECT_PLANETARY_GUN_HIT_ME"
                label = "EFFECT_PLANETARY_GUN_LABEL"
                icon = "icons/meter/damage.png"
                parameters = 
                [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "rawtext" data = ((CurrentTurn / 14 + Target.MaxStructure / 6) +4 - Target.Shield)
                    tag = "ship" data = Target.ID
                ]
                empire = Target.Owner
        ]
    ]
]
icon = "icons/meter/damage.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"
If you give me sets in nested if's, i can probably make a bunch of cool scripts.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Scripting Questions In General

#38 Post by Geoff the Medio »

Geoff the Medio wrote:Fixing it isn't trivial, either.
I've pushed some changes that will hopefully (but probably not completely) fix the issues with meter modifications in if effects. If you can't compile from source, then you'll have to wait for the next text build in a week, unless Vezzra's away by then... then I'm not sure when.

xlightwavex
Space Kraken
Posts: 111
Joined: Mon Nov 16, 2015 5:57 am

Re: Scripting Questions In General

#39 Post by xlightwavex »

Geoff the Medio wrote:
Geoff the Medio wrote:Fixing it isn't trivial, either.
I've pushed some changes that will hopefully (but probably not completely) fix the issues with meter modifications in if effects. If you can't compile from source, then you'll have to wait for the next text build in a week, unless Vezzra's away by then... then I'm not sure when.
A long while ago i built this from source but im probably going to be busy for the next couple days.
If i can get it to build trivially right now ill give it a shot, but probably not as im having a slight hardware issue i think atm or did and im not sure its actually fixed yet. If not sometime in the next few days ill try out the changes and report back the results.

User avatar
Vezzra
Release Manager, Design
Posts: 6095
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: Scripting Questions In General

#40 Post by Vezzra »

Geoff the Medio wrote:...unless Vezzra's away by then...
He already is away... 8)

I will try to provide test builds even while I'm away, but can't make any promises. It all depends if and when I might have remote access to a system where I can build FO. So test builds will be a bit unpredictable for the next few weeks.

xlightwavex
Space Kraken
Posts: 111
Joined: Mon Nov 16, 2015 5:57 am

Re: Scripting Questions In General

#41 Post by xlightwavex »

I got it to build and run just not sure were the installer is. I am running the version i compiled atm though right from the compiled exe.

Have to get far enough in to see how the changes went as i had to start a new game over. It seemed to be working fairly well except the sitreps.

RE: the SetMeter calls appear to be working but im not sure yet as im not sure the damage matches what i see in the sitreps. Its really hard to test when ai ship names are all the same.

Anyways my dl'ed version is from a few days ago so im not sure i got the one with the second set of fixes compiling this takes forever though and i forgot to change the ship name in c++ code thing i asked about earlier.

RE:RE:

Going to re-download everything again and recompile it, i think im seeing delayed destroyed messages but i think it is actually destroying them and the SetMeter is in general working it seems at least damage and messages for it are being displayed.

Something definitely isn't right. It seems like a if effect is executing after the turn or sometimes a msg will, something not sure yet changing my script up to narrow it down.
Last edited by xlightwavex on Sun Oct 02, 2016 11:19 am, edited 2 times in total.

xlightwavex
Space Kraken
Posts: 111
Joined: Mon Nov 16, 2015 5:57 am

Re: Scripting Questions In General

#42 Post by xlightwavex »

Unless im missing something im doing, the effects are repeating and so are the messages the following turn. No matter what i do. I tried activation source and using priority just not working using if else if or even in the final test with just nesting visibility check doesn't seem to make a difference either. Its acting like there are two guns in a system with just one or something sometimes it seems to be delaying or repeating effects and messages or double executing them. So im gonna say its not working right unless you can see something fundamental that would cause that.

Code: Select all

 //Tst 5g


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
        OwnedBy affiliation = EnemyOf empire = Source.Owner         
    ]
    activation = Source
    priority = 76
    effects = 
    [
            
        If condition = and 
        [
            Structure low = 15 
        ]
        effects = 
        [
            if condition = and
            [
                VisibleToEmpire empire = Source.Owner  
            ]
            effects =
            [
            
             SetStructure value = Value - 15 
             SetFuel value = Value -(.5+ Target.MaxFuel / 5)  
     
             //   
             // target damaged msg to the player firing the gun
             //
             GenerateSitrepMessage
                message = "EFFECT_PLANETARY_GUN_HIT"
                label = "EFFECT_PLANETARY_GUN_LABEL"
                icon = "icons/meter/damage.png"
                parameters =
                [
                   tag = "planet" data = Source.PlanetID
                   tag = "building" data = Source.ID
                   tag = "target" data = Target.Owner
                   tag = "ship" data = Target.ID
                   tag = "rawtext" data = 15
                   tag = "targethp" data = Target.Structure
                ]
                empire = Source.Owner
            ]
        ]
        else =
        [
            If condition = and 
            [
                VisibleToEmpire empire = Source.Owner  
            ]
            effects = 
            [
                Destroy
                
                //
                // target destroyed msg for the player firing the gun
                //
                GenerateSitrepMessage
                    message = "EFFECT_PLANETARY_GUN_HIT_DESTROYED"
                    label = "EFFECT_PLANETARY_GUN_LABEL"
                    icon = "icons/sitrep/combat_destroyed.png"
                    parameters = 
                    [
                        tag = "planet" data = Source.PlanetID
                        tag = "building" data = Source.ID
                        //tag = "source" data = Source.Owner
                        tag = "target" data = Target.Owner
                        tag = "ship" data = Target.ID
                        tag = "rawtext" data = 16 
                    ]
                    empire = Source.Owner
            ]
        ]
    ]
]
icon = "icons/meter/damage.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"

Code: Select all


EFFECT_PLANETARY_GUN_LABEL
Planetary Gun

EFFECT_PLANETARY_GUN_HIT
At %planet% the %building% fired on and Hit %empire:target% ship %ship% with %rawtext:targethp% hp causing %rawtext% damage.

EFFECT_PLANETARY_GUN_HIT_DESTROYED
At %planet% the %building% fired on and Destroyed the %empire:target% ship %ship% with a shot for %rawtext% damage.

EFFECT_PLANETARY_GUN_HIT_CLOAK
The %planet% the %building% fired a blind shot and Hit the %empire:target% cloaked ship %ship%.

EFFECT_PLANETARY_GUN_HIT_DESTROYED_CLOAK
The %planet% the %building% fired a blind shot and Destroyed the %empire:target% cloaked ship %ship%.

EFFECT_PLANETARY_GUN_MISSED_CLOAK
At %planet% the %building% fired a blind shot at a suspected cloaked target but scored no hit.

EFFECT_PLANETARY_GUN_HIT_ME
At %planet% the %building% fired on and Hit your ship %ship% causing %rawtext% damage.

EFFECT_PLANETARY_GUN_DESTROYED_ME
At %planet% the %building% fired on and Destroyed your ship %ship%.

EFFECT_PLANETARY_GUN_TARGETING
(testing assert) The %planet% the %building% has targeted the %empire:target% ship %ship% with %rawtext:texta% structure and %rawtext:textb% fuel.

EFFECT_PLANETARY_GUN_TARGET
(testing assert) pgun target %ship% %rawtext:texta% structure and %rawtext:textb% fuel.

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: Scripting Questions In General

#43 Post by dbenage-cx »

Coming together nicely xlightwavex,
Having the visibility check within the effects means a target may be selected that is not visible, resulting in no damage that turn.
I've modified it slightly, adding the ability to hit monsters, which should be easier to test against if you set them to high.

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
    priority = 76
    effects = [
        If
            condition =
                Structure low = 15
            effects = [
                SetStructure value = Value - 15
                SetFuel value = Value -(.5+ Target.MaxFuel / 5) 
                //
                // target damaged msg to the player firing the gun
                //
                GenerateSitrepMessage
                    message = "EFFECT_PLANETARY_GUN_HIT"
                    label = "EFFECT_PLANETARY_GUN_LABEL"
                    icon = "icons/meter/damage.png"
                    parameters = [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "target" data = Target.Owner  // did not troubleshoot this, userstring tag result is ERROR
                    tag = "ship" data = Target.ID
                    tag = "rawtext" data = 15
                    tag = "targethp" data = Target.Structure
                    ]
                    //empire = Source.Owner  // may want to add a sitrep for the target owner as well
            ]
        else = [
            Destroy
            //
            // target destroyed msg for the player firing the gun
            //
            GenerateSitrepMessage
                message = "EFFECT_PLANETARY_GUN_HIT_DESTROYED"
                label = "EFFECT_PLANETARY_GUN_LABEL"
                icon = "icons/sitrep/combat_destroyed.png"
                parameters = [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "target" data = Target.Owner
                    tag = "ship" data = Target.ID
                    tag = "rawtext" data = 16
                ]
                //empire = Source.Owner
        ]
    ]
]
icon = "icons/meter/damage.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"

xlightwavex
Space Kraken
Posts: 111
Joined: Mon Nov 16, 2015 5:57 am

Re: Scripting Questions In General

#44 Post by xlightwavex »

Having the visibility check within the effects means a target may be selected that is not visible
Are you sure wouldn't it simply be redundant ?
// did not troubleshoot this, userstring tag result is ERROR
strange i get no error on running in the console window.

As far as the code its still not a solution, ive marked your version test 6a.
Even though that works for a single conditional switch in the specific order the primary problem is i need to be able to switch on visible or not and low high structure. This is a 1 pick of 4 possible cases, conditional branching problem. Which is why in post #1 the design is using if, else if, else if, else and has both structure and visibile checks as well as not visible The above are all test cases or temporary solutions.

I have however identified the issue. Took forever to figure out what was happening and it will take a minute to explain it. I may have to edit this several times to make it clear.

To summarize the if[] effect[] bracket behavior is inconsistent depending on the level of the nesting.

pseudo illustration

Code: Select all

effect
[ 
  if[]effect[...the set effect will fire once...] 
]
will not behave the same as

Code: Select all

effect
[
  if[]effect
  [
     if[]effect[... the set effect will be fired twice...]
  ]
]
Basically a if condition effect in a effect bracket will fire once.
but another if effect bracket nested within that will fire twice

http://i936.photobucket.com/albums/ad20 ... g~original

Unfortunately this spills over to else if conditions as well.
illustrating the problem side by side we will get 3 hits with 2 guns the if works the else acts as a 3rd level nested effect which fires twice, which is in this case milotha1 the message placement is as well inconsistent to what would be expected with mI then mII then mI messages.
http://i936.photobucket.com/albums/ad20 ... g~original

Consider the following examples.

Ex #1

This will fire each gun one time just like his example above but without the destroy messege.
However this cannot actually make use of a second condition within the if condition[ ... bracket properly ... ]

Code: Select all

 // tst 6f same as 5a 5c  6a single shot visibility is not the problem
 // cant nest with a inner if inconsistent behavior 
 // single nesting
 
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
    priority = 76
    effects = 
    [
        //
        // tst 6f behavior is inconsistent to a switch when a third if is nested 
        // second effect scope is ok
        //
        If condition = and [
                Structure low = 15
        ]
        effects = [
                SetStructure value = Value - 15
                SetFuel value = Value -(.5+ Target.MaxFuel / 5)
                //
                // target damaged msg for the player firing the gun
                //
                GenerateSitrepMessage
                    message = "EFFECT_PLANETARY_GUN_HIT"
                    label = "EFFECT_PLANETARY_GUN_LABEL"
                    icon = "icons/meter/damage.png"
                    parameters = 
                    [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "target" data = Target.Owner  // did not troubleshoot this, userstring tag result is ERROR
                    tag = "ship" data = Target.ID
                    tag = "rawtext" data = 15
                    tag = "targethp" data = Target.Structure
                    ]
                    //empire = Source.Owner  // may want to add a sitrep for the target owner as well
            
        ]
    ]
]
icon = "icons/meter/damage.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"
Ex #2.

This will fire each gun twice on the same target

Code: Select all

 // tst 6e double shot same as 6a 5a visibility is not the problem
 // cant nest with a inner if .. effect[] at level 3 the effect executes twice
 
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
    priority = 76
    effects = 
    [
        //
        // behavior is inconsistent with a switch
        //
        If condition = and [
                Structure low = 15 
        ]
        effects = [
            //
            // tst 6e double shot same as 6a 5a nested if
            // repeated condition which should evaluate to true when the above if does
            // 
            If condition = and [
                 Structure low = 15
            ]
            effects = [
                //
                // unexpected this will execute twice
                //
                SetStructure value = Value - 15
                SetFuel value = Value -(.5+ Target.MaxFuel / 5)
                //
                // target damaged msg for the player firing the gun
                //
                GenerateSitrepMessage
                    message = "EFFECT_PLANETARY_GUN_HIT"
                    label = "EFFECT_PLANETARY_GUN_LABEL"
                    icon = "icons/meter/damage.png"
                    parameters = 
                    [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "target" data = Target.Owner  // did not troubleshoot this, userstring tag result is ERROR
                    tag = "ship" data = Target.ID
                    tag = "rawtext" data = 15
                    tag = "targethp" data = Target.Structure
                    ]
                    //empire = Source.Owner  // may want to add a sitrep for the target owner as well
            ]
        ]
    ]
]
icon = "icons/meter/damage.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"
http://i936.photobucket.com/albums/ad20 ... g~original

Ex#3

The if which works as expected because its not within a third inner nested effect[ .. call ..] is ok, the else here however is not the else[ ..] itself acts like a effects call and adds a nesting level.

Code: Select all

 // tst 6c  no double shot same as 6a visibility is not the problem
 // cant nest this though with a inner if in the else
 
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
        ]
    ]
    activation = Source
    priority = 76
    effects = 
    [
        If
            condition = and 
            [
                Structure low = 15
                Not VisibleToEmpire empire = Source.Owner
            ]
            effects = 
            [
                SetStructure value = Value - 15
                SetFuel value = Value -(.5+ Target.MaxFuel / 5)
                //
                // target damaged msg for the player firing the gun
                //
                GenerateSitrepMessage
                    message = "EFFECT_PLANETARY_GUN_HIT"
                    label = "EFFECT_PLANETARY_GUN_LABEL"
                    icon = "icons/meter/damage.png"
                    parameters = 
                    [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "target" data = Target.Owner  // did not troubleshoot this, userstring tag result is ERROR
                    tag = "ship" data = Target.ID
                    tag = "rawtext" data = 15
                    tag = "targethp" data = Target.Structure
                    ]
                    //empire = Source.Owner  // may want to add a sitrep for the target owner as well
            ]
        else = 
        [
            If
            condition = and 
            [
                Structure low = 15
            ]
            effects = [
                SetStructure value = Value - 15
                SetFuel value = Value -(.5+ Target.MaxFuel / 5)
                //
                // target damaged msg for the player firing the gun
                //
                GenerateSitrepMessage
                    message = "EFFECT_PLANETARY_GUN_HIT"
                    label = "EFFECT_PLANETARY_GUN_LABEL"
                    icon = "icons/meter/damage.png"
                    parameters = 
                    [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "target" data = Target.Owner  // did not troubleshoot this, userstring tag result is ERROR
                    tag = "ship" data = Target.ID
                    tag = "rawtext" data = 15
                    tag = "targethp" data = Target.Structure
                    ]
                    //empire = Source.Owner  // may want to add a sitrep for the target owner as well
            ]
        ]
    ]
]
icon = "icons/meter/damage.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"
http://i936.photobucket.com/albums/ad20 ... g~original

Code: Select all

 // tst 7c bypass attempt
 // cant nest this though with a inner if
 
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
    priority = 76
    effects = 
    [
        //
        // behavior is inconsistent with a switch
        //
        If condition = and [
                Structure high = 15
        ]
        effects = [
            Destroy
            //
            // target destroyed msg for the player firing the gun
            //
            GenerateSitrepMessage
                message = "EFFECT_PLANETARY_GUN_HIT_DESTROYED"
                label = "EFFECT_PLANETARY_GUN_LABEL"
                icon = "icons/sitrep/combat_destroyed.png"
                parameters = [
                    tag = "planet" data = Source.PlanetID
                    tag = "building" data = Source.ID
                    tag = "target" data = Target.Owner
                    tag = "ship" data = Target.ID
                    tag = "rawtext" data = 16
                ]
                //empire = Source.Owner
        ]
        else = 
        [
            If condition = and [
                Structure low = 15
            ]
            effects = [
                
                //
                // tst 7c bypass if[]effect[] syntax required 
                // if[][] if[] ... else[] not possible
                // 
                    SetStructure value = Value - 15
                    SetFuel value = Value -(.5+ Target.MaxFuel / 5)
                    //
                    // target damaged msg for the player firing the gun
                    //
                    GenerateSitrepMessage
                        message = "EFFECT_PLANETARY_GUN_HIT"
                        label = "EFFECT_PLANETARY_GUN_LABEL"
                        icon = "icons/meter/damage.png"
                        parameters = 
                        [
                        tag = "planet" data = Source.PlanetID
                        tag = "building" data = Source.ID
                        tag = "target" data = Target.Owner  // did not troubleshoot this, userstring tag result is ERROR
                        tag = "ship" data = Target.ID
                        tag = "rawtext" data = 15
                        tag = "targethp" data = Target.Structure
                        ]
                        //empire = Source.Owner  // may want to add a sitrep for the target owner as well
            ]
        ]
    ]
]
icon = "icons/meter/damage.png"
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"

7c effect consistency tests
http://i936.photobucket.com/albums/ad20 ... g~original
Last edited by xlightwavex on Mon Oct 03, 2016 5:50 am, edited 2 times in total.

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: Scripting Questions In General

#45 Post by dbenage-cx »

xlightwavex wrote:
Having the visibility check within the effects means a target may be selected that is not visible
Are you sure wouldn't it simply be redundant ?
It may be working off a copy of the universe with only objects that are visible to the source empire, so I am not certain.
If it is working on the full universe: without the VisibleToEmpire check in scope, the target candidates would include any non-visible enemy ships in the system.
In that event, the ship selected as the Target may not be visible to the source owner.
// did not troubleshoot this, userstring tag result is ERROR
strange i get no error on running in the console window.
Erm, my test was vs a monster...which is unowned, my mistake ;)
There was not a console emitted error, the resulting parameter/tag within the string read "ERROR", which is expected in this case.
To summarize the if[] effect[] bracket behavior is inconsistent depending on the level of the nesting.
Good 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.

Post Reply