• Please note: In an effort to ensure that all of our users feel welcome on our forums, we’ve updated our forum rules. You can review the updated rules here: http://forums.wolflair.com/showthread.php?t=5528.

    If a fellow Community member is not following the forum rules, please report the post by clicking the Report button (the red yield sign on the left) located on every post. This will notify the moderators directly. If you have any questions about these new rules, please contact support@wolflair.com.

    - The Lone Wolf Development Team

Using declared but uninitialized and unassigned variables?

ebpatton

Well-known member
In the Weapon Focus feat under General -> Feat in the editor is the following snippet of code:

Code:
        ~ Assign the appropriate tag to all weapons that meet the criteria
        var id as string
        var name as string

        call fTargetId

        foreach pick in hero from BaseWep where "IsWeapon." & id
          perform eachpick.assign[Broadcast.WepFocus]
          nexteach

        foreach thing in BaseWep where "thingid." & id
          perform eachthing.pulltags[wProfReq.?]
          nexteach

        ~ Set our 'short name'
        field[shortname].text = "Focus: " & name
        field[sbName].text = "Weapon Focus (" & lowercase(name) & ")"

        ~ Forward the weapon focus tag for the weapon to the hero
        perform hero.assignstr["WepFocus." & id]

Two variables, id and name, are declared and later used. But neither is initialized. I could maybe believe id is picking up information from the foreach statement, but name doesn't show up at all until it's used in an assignment.

How can name contain the right thing when it's never initialized or assigned to? If it's some sort of global variable, why does it need to be declared? Even if it is global, how does it get its value?

Does fTargetId actually make the assignments to both variables? I could totally believe that. But where then is the procedure defined? I see no reference to it in the Hero Lab Authoring Kit PDF. If it's a useful procedure, how would I know of the existence of other useful procedures like it?

Thank you.
 
I put in debug statements, and I see where the variables are assigned. It's indeed the fTargetId procedure.

The whole post can probably be ignored. I should have just done the debugs before posting, but I didn't think of it.

Sorry.
 
I put in debug statements, and I see where the variables are assigned. It's indeed the fTargetId procedure.

The whole post can probably be ignored. I should have just done the debugs before posting, but I didn't think of it.

Sorry.
No problem at all. Happens as someone is learning. Looks like you getting the hang of the scripting very well actually.

Just to add more info the procedure fTargetId is setting the variables with values. Then it sort of "passes" them back to the calling script from Weapon Focus. This happens because the declaration of "var id as string" line of code.

Procedures are nice because it makes "re-usable" code but the downside is the ones made by LW can not be seen. On the good side in the future if you want you can make your own procedures directly in XML. This makes larger projects nice where the same script code gets used over and over again.
 
Back
Top