How to script conditions for learning spells. Will this work

Post » Thu Aug 25, 2016 4:51 am

I could never get a firm grasp on scripting and coding, so I'm just throwing something I came up with based on what I've seen on the wiki.


trying to make a book only teach a spell if the player's conjuration skill is one hundred!!! ......... This is a regular book and not a spellbook.




Int playerconjuration = Game.GetPlayer().GetAV("Conjuration")

Event OnRead()
If playerconjuration == 100
Game.GetPlayer().Addspell(MysixaySpell)
ElseIf
Debug.Notification("You cannot comprehend the knowledge in this tome.")
EndIf
EndEvent

SPELL Property MysixaySpell Auto



compiling this gives me these errors. Like always I have no idea what any of this means because I do not have Coding Dictionary? 3.0 implanted in my cerebral cortex.



no viable alternative at input 'Game' <--- [censored] cyborg speak

(3,28): required (...)+ loop did not match anything at input '.' <----wtf? why can't programmers say "This doesn't work because of this and that. Do it this way instead."

(3,4): Unknown user flag Game <--- this makes a little more sense, but still moderate cyborg speak.

(8,7): no viable alternative at input '\\r\\n' <---wat?



Is there a sixy way to do this?
User avatar
Elizabeth Falvey
 
Posts: 3347
Joined: Fri Oct 26, 2007 1:37 am

Post » Thu Aug 25, 2016 1:31 am

Try putting parentheses around the condition, because "required (..)". It's still looking for a condition when it hits "Game", which is why it complains that it's not a flag. It knows that it's searched too far because it hit the '.'



Also it's just Else, unless you're doing multiple conditions like this



If (condition1)
...
Elseif (condition2)
...
Else
...
Endif

The '\\r\\n' is return + line feed, the windows standard for "end of line". Since that's not a visible pair of characters it shows the "escaped" version, but with doubled slashes so it doesn't just converted back to invisible. Again, it's looking for something and that's where it gave up.

User avatar
Dark Mogul
 
Posts: 3438
Joined: Tue Feb 20, 2007 11:51 am

Post » Thu Aug 25, 2016 10:47 am

I changed the Elseif to Else and added the parenthethis around the conditions and it threw me the same errors :(



tried If (playerconjuration == 100)

User avatar
Sheeva
 
Posts: 3353
Joined: Sat Nov 11, 2006 2:46 am

Post » Thu Aug 25, 2016 5:28 am

You're trying to initialize an int property outside of an event. Try moving
Int playerconjuration = Game.GetPlayer().GetAV("Conjuration")
inside the OnRead() event.
User avatar
Love iz not
 
Posts: 3377
Joined: Sat Aug 25, 2007 8:55 pm

Post » Thu Aug 25, 2016 2:48 pm

Okay this got me the least amount of compiling errors, but still im getting one error



type mismatch while assigning to a int (cast missing or types unrelated)

No output generated for MyScript, compilation failed.



Event OnRead()
Int playerconjuration = Game.GetPlayer().GetAV("Conjuration")
If playerconjuration == 100
Game.GetPlayer().Addspell(MysixaySpell)
Else
Debug.Notification("You cannot comprehend the knowledge in this tome.")
EndIf
EndEvent

SPELL Property MysixaySpell Auto
User avatar
Deon Knight
 
Posts: 3363
Joined: Thu Sep 13, 2007 1:44 am

Post » Thu Aug 25, 2016 12:47 am

Try this:



Int playerconjuration = (Game.GetPlayer().GetAV("Conjuration") as Int)
User avatar
james kite
 
Posts: 3460
Joined: Sun Jul 22, 2007 8:52 am

Post » Thu Aug 25, 2016 2:37 am


Why cast as an int? You don't really need to make a "player conjuration" variable if you are really only using that command once and don't need to update that variable. Just do



if Game.GetPlayer().GetAV("Conjuration") == 100
;Do the thing
endif

Simple is good. Otherwise the post above would work. When you "cast" your command as an int, you are essentially telling the script engine to output the result of the GetAV() function only as an int, which is why when you don't have "as int" added to it, it fails to compile.

User avatar
Darlene DIllow
 
Posts: 3403
Joined: Fri Oct 26, 2007 5:34 am


Return to V - Skyrim