Lone Wolf Development Forums

Lone Wolf Development Forums (http://forums.wolflair.com/index.php)
-   HL - Pathfinder Roleplaying Game (http://forums.wolflair.com/forumdisplay.php?f=62)
-   -   Scripts: thoughts on Vocabulary versus grammar (http://forums.wolflair.com/showthread.php?t=59704)

Bob G December 5th, 2017 06:38 PM

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?

Minous December 6th, 2017 06:13 AM

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

Minous December 6th, 2017 06:16 AM

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.

Bob G December 6th, 2017 12:03 PM

Quote:

Originally Posted by Minous (Post 259890)
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.

Minous December 6th, 2017 12:32 PM

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.

Aaron December 6th, 2017 12:49 PM

Quote:

Originally Posted by Minous (Post 259913)
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.

Mathias December 6th, 2017 01:04 PM

Quote:

Originally Posted by Bob G (Post 259911)
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.

Minous December 6th, 2017 01:37 PM

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.

Bob G December 6th, 2017 01:54 PM

Quote:

Originally Posted by Mathias (Post 259915)
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:

Bob G December 6th, 2017 01:56 PM

Quote:

Originally Posted by Minous (Post 259916)
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.


All times are GMT -8. The time now is 01:53 PM.

Powered by vBulletin® - Copyright ©2000 - 2024, vBulletin Solutions, Inc.
wolflair.com copyright ©1998-2016 Lone Wolf Development, Inc. View our Privacy Policy here.