BloodSyndicate Posted August 6, 2007 Share Posted August 6, 2007 I've been trying to figure out how to use a variable in multiple scripts. I want one of my Quest scripts to set a constant variable that never changes, and I want other scripts to use this variable. That way, the Quest-Script that sets the variables has to only be run once. Does anyone know if this is even possible? Any help would be appreciated. Link to comment Share on other sites More sharing options...
Vagrant0 Posted August 6, 2007 Share Posted August 6, 2007 I've been trying to figure out how to use a variable in multiple scripts. I want one of my Quest scripts to set a constant variable that never changes, and I want other scripts to use this variable. That way, the Quest-Script that sets the variables has to only be run once. Does anyone know if this is even possible? Any help would be appreciated.If the variable can be expressed with a simple 0,1,2,3,4,5,6 type state, you can use faction ranks on an NPC to have the variable readable and changable from anywhere. You could also use a global variable if the variable requires more numbers to be expressed. There is also http://cs.elderscrolls.com/constwiki/index...etQuestVariable which may or may not work. The difference between the three methods above is that the first allows multiple NPCs to be of that faction, and therefore scripting and packaging can be initiated similarly or differently among those NPCs. The second allows for a single variable to be read or changed from anywhere, with fewer scripting uses, but allows for recording things like crime gold, health, or other large numbers. The third technically allows the same as the second without being able to change it outside that script, but is probably less resource dependant (however I havn't noticed much difference, and havn't had any reason to use getquestvariable for anything). While the third may seem easier to use, it also closes out most options for debugging since that variable can't be changed/read through console. If the variable is a reference, like an actor or object, it cannot be obtained through these ways, and will have to have any functions on that actor called within the same scripting that can define that actor. You can however use other scripts to determine when those functions are called. Link to comment Share on other sites More sharing options...
SephHexenWR Posted August 6, 2007 Share Posted August 6, 2007 I've been trying to figure out how to use a variable in multiple scripts. I want one of my Quest scripts to set a constant variable that never changes, and I want other scripts to use this variable. That way, the Quest-Script that sets the variables has to only be run once. Does anyone know if this is even possible? Any help would be appreciated. This may or may not be what you're looking for. This is the quest script that you assign to the quest:scn ZZQuestConstValue long constValue short doOnce begin GameMode if ( doOnce == 0) set constValue to x set doOnce to 1 endif end Replace x in the set instruction to whatever it is you need. You access the variable by typing questname.constValue rather than just constValue, where questname is the editor ID of the quest. Hope this helped. Link to comment Share on other sites More sharing options...
BloodSyndicate Posted August 6, 2007 Author Share Posted August 6, 2007 Well, one of the first things i tried was the GetQuestVariable calling function. I would use the same syntax that you just mentioned.. yet its a condition function only.. From what ive read quests use it to activate certain states, and the variable is always a 1 or 0. The QuestVariable isnt something you can declare in a script anyways, as far as I can tell. If you try and use a script variable, even from a quest-script, it will not work. And the problem with Global Variables is you cannot set them in a script. And I need more number range than 1 to 6. Link to comment Share on other sites More sharing options...
Vagrant0 Posted August 6, 2007 Share Posted August 6, 2007 And the problem with Global Variables is you cannot set them in a script. And I need more number range than 1 to 6.You can set globals through scripting, the variable just has to be defined within the globals box, and not within the actual script. If you declare a variable with the same name in that script, it won't work right. My fighters guild mod uses a global variable to control the open cities state, it both reads and changes that variable. Link to comment Share on other sites More sharing options...
BloodSyndicate Posted August 6, 2007 Author Share Posted August 6, 2007 And the problem with Global Variables is you cannot set them in a script. And I need more number range than 1 to 6.You can set globals through scripting, the variable just has to be defined within the globals box, and not within the actual script. If you declare a variable with the same name in that script, it won't work right. My fighters guild mod uses a global variable to control the open cities state, it both reads and changes that variable.I dont think I understand you completely. You said you can set global variables using the globals box? I dont think that is in a script. Yes you can make new globals and set them in the mod, but I mean change them in real time with a script. Link to comment Share on other sites More sharing options...
Vagrant0 Posted August 7, 2007 Share Posted August 7, 2007 I dont think I understand you completely. You said you can set global variables using the globals box? I dont think that is in a script. Yes you can make new globals and set them in the mod, but I mean change them in real time with a script.Yes, you can, and I have. Below is the script I mentioned in its entirety, now with notations, the global which it reads, and alters is VGOCChorrol. This variable is defined in the globals box, it does seem like I have some planned redundancy so that the value of the global is also stored within each script that uses it. This may not be needed, but like most everything within that mod, it had redundancies built in to prevent any sort of bugs from popping up in the scripting. By this way, both the local and global variable would always agree, if there is disagreement, the script would update the local variable to match the global. scn VG0RotationTrackerscript ;this script handles some of the background actions. Could also be used to trigger certain event actions. short stage short var1 short var2 short day short day3 short ChorrolTest short ChorrolDeadman ;starts with initial definitions and adjustments. There is still the remains from when chorrol was OpenCities ;compatable, while I don't intend to make other cities follow, I have left the scripting incase I need to do ;something similar later. begin gamemode set stage to getstage VG0RotationTracker if stage ==0 setstage VG0RotationTracker 1 ChorrolFGPorterREF.setfactionrank VG0DutyGroup 0 SkingradFGPorterREF.setfactionrank VG0DutyGroup 0 IlavDralgonerRef.setfactionrank VG0DutyGroup 0 AnvilFGPorterREF.setfactionrank VG0DutyGroup 0 set day to GameDaysPassed set ChorrolTest to VGOCChorrol set day3 to 0 endif ;basically resets everyone's factions incase other resets didn't trigger. Since this was one of the main ;controlling points it has triple redundancy (here, and twice on the NPC) to avoid breaking. if gamehour <=6 && GameDaysPassed > day ChorrolFGPorterREF.setfactionrank VG0DutyGroup 0 SkingradFGPorterREF.setfactionrank VG0DutyGroup 0 IlavDralgonerRef.setfactionrank VG0DutyGroup 0 AnvilFGPorterREF.setfactionrank VG0DutyGroup 0 VG0SylviaRef.setfactionrank VG0DutyController, 0 VG0SvenRef.setfactionrank VG0DutyController, 0 VG0PricaRef.setfactionrank VG0DutyController, 0 VG0JamalRef.setfactionrank VG0DutyController, 0 VG0TessaRef.setfactionrank VG0DutyController, 0 set day to GameDaysPassed if chorroldeadman != 1 set day3 to day3+1 endif endif ;section dealing with Open Cities. Detects where some NPCs are, then from there determines if that mod is ;also in use. The problem with adding more cities seemed to be involved with a complicated IF statment ;detecting what towns were tested or not. Could have probably been broken down into seperate blocks ;to avoid the problem, but as those mods have gone out of use, wasn't seen as useful. if ChorrolTest != VGOCChorrol if VGOCChorrol == 0 ;message "The gates of Chorrol can be heard closing nearby." VG0ChorrolPack01Marker.positionworld -66166, 97586, 14482, 0, ChorrolWorld elseif VGOCChorrol == 1 ;message "You feel a slight change in the wind." VG0ChorrolPack01Marker.positionworld -66166, 97586, 14482, 0, Tamriel endif set ChorrolTest to VGOCChorrol endif if player.getinworldspace chorrolworld == 1 set VGOCChorrol to 0 elseif player.getdistance VG0ChorrolTreeresetmarker <= 3500 set VGOCChorrol to 1 set chorroldeadman to 1 elseif CastaScriboniaRef.getdistance VG0ChorrolTreeresetmarker <= 3500 set VGOCChorrol to 1 set chorroldeadman to 1 endif ;basically a failsafe, if the NPCs weren't in the world, or the player never entered chorrol, it would assume ;that the mods weren't present. if VGOcchorrol == 1 if day3 >= 3 if chorroldeadman != 1 set VGOCChorrol to 0 set chorroldeadman to 1 ;message "Backup triggered." endif endif endif end However if you explained what exactly you needed this variable to control or how it is being set, read, and altered, I could probably tell you exactly how you could do it. Link to comment Share on other sites More sharing options...
BloodSyndicate Posted August 7, 2007 Author Share Posted August 7, 2007 Vargrant: From your script I can see basically what it is your doing. But, you only used the VGOChorrol variable to store 2 different numbers - 0 and 1. Im assuming for yes and no. Can the global variables store more numbers, with higher decimals? Im simply trying to save confusion with my scripts, and save cpu time. The initial script sets the players birth attributes. So that when you use an existing save it can detect your players initial attributes, and remember them, so if i need to change a players attributes later, I can always know their birth attributes, if necessary. Ive actually already completed the script. Basically it gives the player bonus speed, all while detecting the players basespeed without the bonus. and the bonus will eventually diminish after the players basespeed reaches 100. The whole purpose of this script is to balance the effects of lowering a game setting. fMoveCharWalkMin. By Default it was 90, now it is 22.5, 25% of the original value. NPCs are adversely effected since they dont get the bonus from the script. But spells that drain, damage, and fortify speed have up to 75% effect on your speed, when before the effect was minimal. Anyways, thanks for you help. Link to comment Share on other sites More sharing options...
Vagrant0 Posted August 7, 2007 Share Posted August 7, 2007 Im simply trying to save confusion with my scripts, and save cpu time. The initial script sets the players birth attributes. So that when you use an existing save it can detect your players initial attributes, and remember them, so if i need to change a players attributes later, I can always know their birth attributes, if necessary.Variables cannot be applied across multiple games, when used on an existing save, it wouldn't record the base attributes, but the value that was currently present at the time of that save, including any existing bonuses from spells or enchantments. Even if it's a global, that value only exists within that single game. As far as globals go, each value would have to be stored individually http://cs.elderscrolls.com/constwiki/index...egory:VariablesHowever I don't think that what you want to happen will really work that way. You might just have to guesstimate the amount of a speed bonus you want to give the player based off level, using an ability instead of actually changing the players base stat. Link to comment Share on other sites More sharing options...
SephHexenWR Posted August 7, 2007 Share Posted August 7, 2007 I should bring up that if you're ever using a global for a strict true/false statement, that might not be best as all globals are supposedly stored internally as floats, which are known to be pretty inaccurate. That's just a side note I didn't see explicitly mentioned here (unless I missed it, of course). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.