Hello there. I don't mean to hijack this thread, but can you explain the first 2 lines defining both player and ale properties? I'm trying to get into scripting, and I can't wrap my head around this part. The player and ale exist, why do they need defining? Why can't we just directly access the player's inventory? I really feel I'm missing a key concept.
Properties allow scripts easy access to things in the game. While the player and ale do exist, they exist in the game. A script is separated, to a degree, from the game, but the script can interact with the game. Let's say that you used this script instead:
Actor PlayerPotion AlePlayer.Additem(Ale, 1)
What do you have here? You have two variables, Player and Ale. The former accepts objects of the type actor and the latter accepts objects of the type potion. The problem is that these variables have nothing assigned to them, yet. The script doesn't know who Player refers to and what Ale is. The Player variable could be defined as the player character by adding the following line:
Player = Game.GetPlayer()
Actor PlayerPotion AlePlayer = Game.GetPlayer()Player.Additem(Ale, 1)
Now the script knows who to add the item to, but the item is still unknown. We need to find a way to define Ale as the object ale that is found in the game. As amgepo posted earlier, you could use:
game.getform(0x00034c53) as potion
Actor PlayerPotion AlePlayer = Game.GetPlayer()Ale = Game.GetForm(0x00034c53) as potionPlayer.Additem(Ale, 1)
If you use properties, then you can do a few really useful things:
- Write shorter scripts (fewer, or no, things to define in the script itself)
- Easily link variables to things in the game (no need to figure out the FormID)
- Make a single, generally applicable, script that can be used in several instances with the possibility of properties referring to different objects on a case by case basis