User Tools

Site Tools


sharedvalue_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
sharedvalue_example [2020/02/09 20:26]
credzba [Example Usage]
sharedvalue_example [2020/07/06 03:29] (current)
Line 1: Line 1:
 ====== Set Shared Value ====== ====== Set Shared Value ======
 +<​code>​
 Misc.SetSharedValue("​Key",​ "Some value set for key") Misc.SetSharedValue("​Key",​ "Some value set for key")
 +</​code>​
  
 ====== Get that Shared Value====== ====== Get that Shared Value======
 +<​code>​
 test = Misc.ReadSharedValue("​Key"​) test = Misc.ReadSharedValue("​Key"​)
 # test should now contain "Some value set for key" # test should now contain "Some value set for key"
 +</​code>​
  
 ====== Example Usage====== ====== Example Usage======
 +
  
 In practice I use this to dynamically affect script behavior. ​ In practice I use this to dynamically affect script behavior. ​
 +
 For instance I have a fight script that I want to sometimes use whirlwind and sometimes use momentum based on the fighting situation. I don't want to stop mid fight and change the script, and I don't want to copy the whole script just to get this ability to change behavior. ​ For instance I have a fight script that I want to sometimes use whirlwind and sometimes use momentum based on the fighting situation. I don't want to stop mid fight and change the script, and I don't want to copy the whole script just to get this ability to change behavior. ​
    
-<​code>​ 
 In my fight script I have: In my fight script I have:
 +<​code>​
 if Misc.CheckSharedValue("​UseMomentum"​):​ if Misc.CheckSharedValue("​UseMomentum"​):​
     use_momentum = Misc.ReadSharedValue("​UseMomentum"​)     use_momentum = Misc.ReadSharedValue("​UseMomentum"​)
Line 23: Line 28:
 else: else:
     Use_weapon_special(weapon)     Use_weapon_special(weapon)
 +</​code>​
  
 Then, in another script attached to a hot key: Then, in another script attached to a hot key:
 +<​code>​
 if Misc.CheckSharedValue("​UseMomentum"​):​ if Misc.CheckSharedValue("​UseMomentum"​):​
-    Misc.SetSharedValue("​UseMomentum",​ Misc.GetSharedValue("​UseMomentum"​))+    Misc.SetSharedValue("​UseMomentum", ​not(Misc.ReadSharedValue("​UseMomentum"​)))
 else:    ​ else:    ​
     Misc.SetSharedValue("​UseMomentum",​ False)     Misc.SetSharedValue("​UseMomentum",​ False)
-<\code>+ 
 +Mobiles.Message(Player.Serial,​ 5, "Use Momentum: {}"​.format(Misc.ReadSharedValue("​UseMomentum"​))) 
 +</code>
  
sharedvalue_example.txt · Last modified: 2020/07/06 03:29 (external edit)