Scripts: thoughts on Vocabulary versus grammar
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. |
Quote:
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. |
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 |
Quote:
|
Quote:
|
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.
|
Quote:
Thanks for that. I feel like a two year old learning how to talk...:confused: |
Quote:
Thanks everyone. |
All times are GMT -8. The time now is 06:21 PM. |
Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.