• 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

Scripts: thoughts on Vocabulary versus grammar

Bob G

Well-known member
I think the toughest part of learning to write eval scripts has been learning how to put 'sentences' together that make sense to the editor. I think I have a basic understanding of the vocabulary needed (I get what tags, fields, macros, things, etc. are), but I think I am still lacking the knowledge of how to put that vocabulary together to make a 'language' that is understandable.

For example, I might know the words in Spanish for 'I', 'eat', 'cookie', and 'want', but if I don't know what order to put them in, the resulting sentence will probably be meaningless. My experience with writing scripts has been very much like this; I know 'words' like 'field' and 'cBbnRage', but writing a 'sentence' like "apply a bonus to damage equal to the character's Intelligence bonus with all firearms" still eludes me.

Is there a tutorial or thread on the forums that teaches the 'grammar' of scripts?
 
http://forums.wolflair.com/showthread.php?t=21688

Keep in mind that you are programming, not using what humans call language. The primary difference is that you are giving commands to the system, not communicating with it. Also keep in mind while apply a bonus to damage equal to the character's Intelligence bonus with all firearms might be one sentence for humans its a matter of 4-5+ commands for HL
 
the sudo code for apply a bonus to damage equal to the character's Intelligence bonus with all firearms is something like:

find intelligence modifier and store in variable.

find all fire arms, and iterate over those (a for each loop)
apply damage modifier to said weapon.
end the for each loop

and you would need to set the timing of that command correctly, Somewhere after post attributes probably.
 
the sudo code for apply a bonus to damage equal to the character's Intelligence bonus with all firearms is something like:

find intelligence modifier and store in variable.

find all fire arms, and iterate over those (a for each loop)
apply damage modifier to said weapon.
end the for each loop

and you would need to set the timing of that command correctly, Somewhere after post attributes probably.

So, if I'm thinking this through correctly, and following your steps, I would first get the INT attribute bonus:
field.[abValue]=hero.child[aINT].field[aBonus].value

Then, I would do a foreach command that locates all picks with the BaseWep component and the tag wCategory.Firearm:
foreach pick in hero from Component.BaseWep where wCategory.Firearm

Then, I apply the bonus to the results that the foreach command found:
eachpick.field[dmrBonus].value += hero.child[aINT].field[abValue].value

Lastly, I end the foreach command:
nexteach

I haven't tried it yet, just wanted to get my thoughts written down so that it sticks in my mind. Let me know if my script was right, and thank you so much for your help.
 
Last edited:
It looks right, but I haven't tested it. I also wouldn't use abValue for basic variable usage.

I would do something like:
Code:
var int_bonus as number
int_bonus = hero.child[aINT].field[aBonus].value
foreach pick in hero where wCategory.Firearm
       eachpick.field[dmrBonus].value += int_bonus 
nexteach

I will also note that the fields you are using may or may not be correct, I dont have HL handy to confirm.
 
Last edited:
It looks right, but I haven't tested it. I also wouldn't use abValue for basic variable usage.

I would do something like:
Code:
var int_bonus as number
int_bonus = hero.child[aINT].field[aBonus].value
foreach pick in hero where wCategory.Firearm
       eachpick.field[dmrBonus].value += int_bonus 
nexteach

I will also note that the fields you are using may or may not be correct, I dont have HL handy to confirm.

In my opinion, its always much better to store a value used in a field than in a variable. Fields can be manipulated from the outside, while variables can't. For the same reason it's also best practices to split your eval scripts so that the first sets values, and the second uses those values, with some time in between in case something needs to intervene.
 
field.[abValue]

In the link Minous gave you, follow the second link - the Location, Location, Location article, and then take another look at the syntax for the field transition. What you've got here is not correct.
 
Aaron the only reason I suggested a variable was for readability purposes. I find int_bonus far easier to remember then what hero.child[aINT].field[aBonus].value is referring to. Had this been a more complex request or a scaling value I would agree. But for what is just a simple reference value that is not going to be used outside of the script I felt that limiting the scope using a variable was appropriate.
 
In the link Minous gave you, follow the second link - the Location, Location, Location article, and then take another look at the syntax for the field transition. What you've got here is not correct.

Yessir, you are right. Should be field[abValue].value

Thanks for that. I feel like a two year old learning how to talk...:confused:
 
Aaron the only reason I suggested a variable was for readability purposes. I find int_bonus far easier to remember then what hero.child[aINT].field[aBonus].value is referring to. Had this been a more complex request or a scaling value I would agree. But for what is just a simple reference value that is not going to be used outside of the script I felt that limiting the scope using a variable was appropriate.

It's all good, either way. I've learned that there are two ways to accomplish the task, and that's a good thing.

Thanks everyone.
 
In the link Minous gave you, follow the second link - the Location, Location, Location article, and then take another look at the syntax for the field transition. What you've got here is not correct.

'Location, location, location' was a very helpful tutorial Mathias, thanks for writing it. I have a question about the foreach command: When you indicate to insert a tag ID in place of "test expression", do you use the full tag ID, or just the extension (what follows after the ".")?

Example: Do I use

foreach pick in hero where wCategory.Firearm

or just

foreach pick in hero where Firearm
 
Aaron the only reason I suggested a variable was for readability purposes. I find int_bonus far easier to remember then what hero.child[aINT].field[aBonus].value is referring to. Had this been a more complex request or a scaling value I would agree. But for what is just a simple reference value that is not going to be used outside of the script I felt that limiting the scope using a variable was appropriate.
The other way to keep things easier to read is to use Macros. So the above aInt stuff can be shortened to:
Code:
field[abValue].value += #attrbonus[aINT]

The above macro gets pretty much turned into hero.child[aINT].field[aBonus].value by the compiler. I find the ability to remember #attrbonus[] or #attrbonus1[] or #attmod[] much easier than remembering the field names. ;)
 
'Location, location, location' was a very helpful tutorial Mathias, thanks for writing it. I have a question about the foreach command: When you indicate to insert a tag ID in place of "test expression", do you use the full tag ID, or just the extension (what follows after the ".")?
The Full tag (ie the word before the period and after). Your constructing a "Custom Expression" at that point.

Take a look at THIS post I did about doing that. Hopefully it helps. :)
 
The other way to keep things easier to read is to use Macros. So the above aInt stuff can be shortened to:
Code:
field[abValue].value += #attrbonus[aINT]

The above macro gets pretty much turned into hero.child[aINT].field[aBonus].value by the compiler. I find the ability to remember #attrbonus[] or #attrbonus1[] or #attmod[] much easier than remembering the field names. ;)

that would require me to remember the scripts, something that I dont always do.
 
Back
Top