Michaellok Posted March 25, 2018 Share Posted March 25, 2018 I need a script. When reading a book, change the value of a global variable. Link to comment Share on other sites More sharing options...
RichWebster Posted March 26, 2018 Share Posted March 26, 2018 (edited) Create a script on the book as follows: GlobalVariable Property YourGlobalName Auto Bool bIsRead = False Event OnRead() If ! bIsRead YourGlobalName.SetValue(YourValue) bIsRead = true EndIf EndEvent Edited March 26, 2018 by B1gBadDaddy Link to comment Share on other sites More sharing options...
agerweb Posted March 26, 2018 Share Posted March 26, 2018 Don't forget the first line: Scriptname ChangeGlobalOnReadScript extends ObjectReference The name I have invented but it can be anything you like. Link to comment Share on other sites More sharing options...
DMan1629 Posted March 26, 2018 Share Posted March 26, 2018 Create a script on the book as follows: GlobalVariable Property YourGlobalName Auto Bool bIsRead = False Event OnRead() If ! bIsRead YourGlobalName.SetValue(YourValue) bIsRead = true EndIf EndEvent I actually have a problem with this...I made a similar mod (about a spell) and the variable "bIsRead" is tricky, here's why (this might not be true for this code!!!):Whenever the script stops running, the value of "bIsRead" is lost because it's a local variable.I have tried doing this as an ActiveMagicEffect though, so it might be different for ObjectReference.My suggestion is you implement this script but add a notification to pop up right below the line YourGlobalName.SetValue(YourValue) After that, try to open and close the book multiple times (with different intervals) and see if the notification pops up only on the first try.If not - you'll need another global variable instead. Just wanted to make a small point just in case :D Link to comment Share on other sites More sharing options...
Michaellok Posted March 26, 2018 Author Share Posted March 26, 2018 (edited) I make This: Scriptname AprenderReceita extends ObjectReference GlobalVariable Property Receita AutoFloat Property Aprender AutoBool bIsRead = False Event OnRead() If ! bIsRead Receita.SetValue(Aprender) bIsRead = true EndIfEndEvent But "Receita" don't recive "Aprender" Edited March 26, 2018 by Michaellok Link to comment Share on other sites More sharing options...
JonathanOstrus Posted March 26, 2018 Share Posted March 26, 2018 I make This: Scriptname AprenderReceita extends ObjectReference GlobalVariable Property Receita AutoFloat Property Aprender AutoBool bIsRead = False Event OnRead() If ! bIsRead Receita.SetValue(Aprender) bIsRead = true EndIfEndEvent But "Receita" don't recive "Aprender"Are the properties set in the CK section for the properties on the script? Is the reference of the book you're trying to read a new one or one already spawned in the save? Note only new spawns of the object will have the script. Spawns that exist prior to loading the mod which adds the script will not have it. Lastly do you get any errors in the papyrus log? Link to comment Share on other sites More sharing options...
RichWebster Posted March 26, 2018 Share Posted March 26, 2018 Create a script on the book as follows: GlobalVariable Property YourGlobalName Auto Bool bIsRead = False Event OnRead() If ! bIsRead YourGlobalName.SetValue(YourValue) bIsRead = true EndIf EndEvent I actually have a problem with this...I made a similar mod (about a spell) and the variable "bIsRead" is tricky, here's why (this might not be true for this code!!!):Whenever the script stops running, the value of "bIsRead" is lost because it's a local variable.I have tried doing this as an ActiveMagicEffect though, so it might be different for ObjectReference.My suggestion is you implement this script but add a notification to pop up right below the line YourGlobalName.SetValue(YourValue) After that, try to open and close the book multiple times (with different intervals) and see if the notification pops up only on the first try.If not - you'll need another global variable instead. Just wanted to make a small point just in case :DWith object references the variable will stick around forever unless it's reset by something else. Magic effects are different :) Link to comment Share on other sites More sharing options...
Michaellok Posted March 26, 2018 Author Share Posted March 26, 2018 My intention is that when reading a book the character can create an item. Link to comment Share on other sites More sharing options...
FrankFamily Posted March 26, 2018 Share Posted March 26, 2018 (edited) Even if the variable is lost it doesn't matter. It will just set the global again to the value it already has, this happening only the first time you read it after it was reseted. How many times is the player going to read the book? This scenario is not really a problem. I'm not 100% sure but if the object isn't a persistent reference I don't think the variable will stick forever. But as said above it doesn't matter. Edited March 26, 2018 by FrankFamily Link to comment Share on other sites More sharing options...
Michaellok Posted March 29, 2018 Author Share Posted March 29, 2018 (edited) I make This: Scriptname AprenderReceita extends ObjectReference GlobalVariable Property Receita AutoFloat Property Aprender AutoBool bIsRead = False Event OnRead()If ! bIsReadReceita.SetValue(Aprender)bIsRead = trueEndIfEndEvent But "Receita" don't recive "Aprender"Are the properties set in the CK section for the properties on the script? Is the reference of the book you're trying to read a new one or one already spawned in the save? Note only new spawns of the object will have the script. Spawns that exist prior to loading the mod which adds the script will not have it. Lastly do you get any errors in the papyrus log?I spawned a book using the console, but the script din't work. Edited March 29, 2018 by Michaellok Link to comment Share on other sites More sharing options...
Recommended Posts