Talk:MessageBox Tutorial

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search

OK, what exactly is there on here that is potentially wrong information? I admit to not having gone through it thoroughly since I am not up to date on all of the problems in dealing with messageboxes, although I have corrected the spell script menu thing (and linked within the article to the appropriate section). I do think that the scripting seems to be unnecessarily complicated, but I haven't done much with messageboxes.

--ShadowDancer 14:11, 24 August 2007 (EDT)

Just the one problem, and it only comes up if you have the activator do more than move back to the starting cell when everything ends (Choosing == 0). I've used all of this in my mods, so I know that every part works (barring typos, but I've cut and paste quite a bit of this into new mods without problems). I know it's complex, but that's what makes it bulletproof, expandable, and a template for any menu system.
More general - I (well, I wouldn't mind help) keep putting aside rewriting this, because, well, I do have to rewrite it (different flow, examples, etc.). Until then, while I very reluctantly agree that the different versions of the script need to be done (spell, quest, token), I think it would be easier to keep them in an external link, with an explanation of the difference between the activator and spell version, as the flow is supposed to work towards one all-purpose script.
Let me know what you think about that setup (I'll help anyway I can)
I had purposely avoided quests, spells, and tokens. There's nothing they can do that an activator can't, and activators are simply superior - quest variables can be reset (StartQuest on an already running quest will reset the variables, and I've heard that adding new variables requires resetting the quest, though that's unverified and there are other possible explanations), tokens can't keep persistent variables, and spells are simply a pain (duration, etc.). The cost - having to move the activator around. It's a bit moot anyway, as people keep asking for the different versions.
--Haama 16:47, 24 August 2007 (EDT)
I can agree that an activator can be superior in certain instances. However, there is one major problem with activators that does not show up in spell scripts - Numerous GameMode blocks. In my opinion, it would be easier to write a spell script, and have the activator cast it in some instances, in order to reduce the number of GameMode blocks that are constantly running. In a larger mod (or in multiple mods), this could cause slow down if there are enough GameMode blocks running, even with Return statements (although it would admittedly be a huge number of GameMode blocks).
--ShadowDancer 00:37, 25 August 2007 (EDT)
oO, huh? The GameMode block runs 2 'if' statements (if Choosing == 0 and if Reset == 0) before stopping, and more importantly it's in a remote cell when it's not being used. Guidobot suggests that activators in remote cells run once every 30 seconds, and from what I've seen I think they were only running because he was setting a variable on the activator every 30 seconds. I've been meaning to test 'set' versus 'if', so I'll see how many it takes before a problem is reached (I've had to run functions 10000/frame before seeing a difference, so I'll see).
Full devil's advocate mode - The problems people run into have almost always stemmed from a script that works for one situation (single menu usually), but not for theirs. I think the tutorial should work towards one, and only one, script that can be used for any messagebox system - multiple menus, etc. A spell cannot be used for multiple menus, as you never know how much the player will go back and forth between menus, and it takes around 15 frames in GameMode before their decision is caught by GetButtonPressed (so .25-1 second for each new menu). Also, spells will not start until GameMode, limiting their functionality, and they cannot store persistent variables. For these reason, I think it would be better to discourage people from using spells (even to the point of not posting scripts) as they would lead to more questions than working scripts.
I think a token or quest system might be plausible, however. A quest system would also need to run every frame (well, at least I find the delay from StartQuest unusable), and a token system would need to set variables on another persistent object (though it would probably be easier to conceptualize). I really believe that only one type of system needs to be in the tutorial. The only reason I have a heart for, is that people might not want to learn another system. In this case, though, I think the article needs to be rewritten to convince them other methods work and are easy, rather than separate articles or sections.
--Haama 01:41, 25 August 2007 (EDT)
If you have looked at the number of mods that some people claim to be running (I have seen lists of 50+ on the forums), there could be an impact if multiple GameMode blocks are running at the same time in most of them. That is how my thinking is working for purposes of this discussion. Additionally, there is no telling if all of the safeguards that you or I, as experienced scripters, would place in GameMode blocks are being used in those mod's GameMode blocks. I believe that at one point there was a discussion about the effects of GameMode blocks on game performance and whether or not the active GameMode blocks processed the whole script, even if it didn't actively do anything at the moment. If I remember correctly, it was determined that all of the lines were processed even though the game engine didn't have anything to do - basically a Return statement didn't exit GameMode, it just deactivated the computing of the following lines which were still read. I could be wrong, but I thought that was what was determined. DragoonWraith may remember more of the discussion? Anyway, my point of thought is that running in GameMode can be like an addicting drug for some people, to the point where a "great idea" takes over and causes a game to go from 60 FPS to 12 FPS. Admittedly it probably won't happen in a MessageBox script. And Guidobot could be right, I haven't tested the effects of GameMode in a remote cell other than making sure that GameMode wasn't running a complicated math script without the PC present (I made a little solar system, LOL!)
Aside from that, the simple solution to a spell script is either to not allow them to go from one menu to another to a previous menu, or to up the time on the spell and save the result for the ScriptEffectFinish. Setting a variable, and maybe an effect shader, both resolving during the spell completion, should take care of the "wasted time" as the spell is "working its magic to accomplish the caster's desire". For instance, Raziel23x was working on a script that required the use of multiple menus to do what he wanted just due to the numerous choices. Since it is a spell script, it is just easier to use the ScriptEffectxxx to perform the task in my opinion.
Tokens on the other hand, may have issues of their own. At least, adding and removing them quickly has been implicated in CTDs.
Quest scripts only run every 5 seconds, probably due to the number of quests in the game that could be running simultaneously.
While it may be true that one menu system could theoretically cover pretty much any circumstance, I would personally go for the simpler script construction. If you are letting people decide how much of your script to choose, which is what ends up happening with a tutorial, you can't guarantee that they will use the whole script. This might cause issues when someone is running multiple mods if the activator isn't removed to a remote cell in some of them. My personal choice would be to show various examples, explain the possible pitfalls of the examples, and leave the type of script choice up to the individual since they are going to choose how they are going to script it anyway.
--ShadowDancer 05:59, 25 August 2007 (EDT)

Yeah, I'll ask DW. If it's from before OBSE's looping and GetNumItems, then I don't see how they could have tested for it - I haven't seen anything that makes enough of a dent in FPS to tell that the script is still "silently" processed.

Speaking of which, I'm not talking about 50, or 100 times being a problem - I'm talking about 1000s before you can even see a fraction of an FPS lost. With a test version of the Inventory Tracker, I ran 1000 'set' function, over 3000 'if' functions, and a few other functions every frame and I couldn't even tell it was activate. I assume that there was a partial of an FPS taken, as I could see the difference when I doubled everything, but it's lost in the noise of random FPS variation.

Good thinking on the spell script, that'd make it work. Just make sure that everything is set back to 0 when the player really exits the menu, or else you'll keep repeating the last step.

For now I'm going to alter the spell script to make it more all-purpose, and place a warning that using it for multiple menus hasn't been tested (I trust you'll take it down/alter it once you've got it working). I think that when I rewrite this, I'll use general examples, or a token example, and then branch out and explain the 4 methods of running the messagebox.

--Haama 10:03, 25 August 2007 (EDT)

About the edits - I deleted the preamble because it contained misleading information - the first menu is in the Update block so the player can return to it later, not for clarity. I put the -, + Choosing stuff back in to go with the rest of the article. I tried to move away from a 'step' concept to show modders that a 'tree' can be used, that will lend itself better to multiple layers. Also, I changed how the button capture process worked. Although rare, sometimes you need to run thorugh 'Choice == X' multiple times before continuing (usually when the modder doesn't use OBSE, and can't use loops), which would have the button reset to -1 after the first time. Finally, I got rid of the multiple Button variables, as they're misleading (you can still only get a non -1 number once).
Also, did I do the recasting of the spell correctly? Should I Dispel the spell once the player exits the menu?
--Haama 10:30, 25 August 2007 (EDT)
I will admit that I haven't really been following this - after DangerSense, I really don't ever want to touch a menu system again. ShadowDancer, you mentioned early on that the script seems overly complicated - that's because it is, but it's not haama's fault, it's Bethesda's. MessageBox is a very poor way to make menus, but it's all we have.
Anyway, regarding performance. I run about 130 mods, and a lot of them are script heavy (Supreme Magicka, Locational Damage, Deadly Reflexes, Sudden Violence, Multitude of Magecraft, Lost Telvanni Codex, Midas Magic, etc etc), and I have never seen any impact from scripts. I have a reasonably strong computer, but I really mean no effect from scripts. Oblivion's script processing is, in my opinion, rather efficient. Graphical mods (texture replacers), things that add a lot of NPCs in one place, things with lots of physics going, those are the things that slow down Oblivion. If you think about it, every NPC in the game is running code far more complicated than any script, even with the dumbed down Radiant AI, and you often have a dozen or more NPCs in a city at once. I think you would have to be trying to compete with that with script. I have seen people do tests of this, by the way - spawning a bunch of scripted objects around the player, all running scripts - and it was unnoticable.
As for spells for MessageBox menus, I think that sounds like a terrible idea. Same with tokens. I used a Quest for DangerSense, but now that we know about the variable resetting, I think Activators are the only way to go. Tokens are just unnecessary (the whole point of a token is to run the script on every actor, but only the player can interact with MessageBoxes - why one earth would it be on a token? Spells are pretty much the same in this regard, but they also add the major headache of a time limit. I think really that we should strongly recommend that people use activators for this.
Dragoon Wraith TALK 10:50, 25 August 2007 (EDT)
I understand the reluctance, and hopefully people won't feel the same after reading this tutorial. Anyway, I've rewritten the Intro and Basics sections. I'll get to the other sections later, but hopefully it's an improvement.
--Haama 15:27, 25 August 2007 (EDT)
I, too, can understand your reluctance. And I agree that you are right about the effects of GameMode in a MessageBox script. However, if you are writing something that needs a menu and is a magic-type effect, I don't see an issue with using a Magic Effect script. Unless someone is totally indecisive, they should be able to navigate a few menus to get to the choice they want within a few seconds, so a 30 second Duration should be sufficient in most cases and it can simplify the scripting. My thinking on using Magic Effect scripts is that if you have a spell that you want to do something, there is no reason to include activators if they aren't needed. Raziel23x's script is the perfect example if you wanted to make a spell that could reset values on the Accomplishments tab of the Stats Menu. I'm not sure why you would want to do it, but he did, so I helped him with the menus. The issue it brings up, however, is that the existing MessageBox Tutorial didn't cover this information in a usable format for spells without reworking.
--ShadowDancer 00:18, 26 August 2007 (EDT)
I can live with however you want to do this section. After some sleep and thinking more about it, if I were writing a script myself, I would probably introduce a variable controlled section using Choice to introduce an effect shader at the choice of the menu item, probably create a timer to allow for the full shader effect, end the effect shader, and then use Dispel to dispel the script which would make the ScriptEffectFinish section redundant, but that doesn't really fit into what this tutorial is concerned about other than if you used a spell script. If you dispel the script, you can adjust up the timer on the spell and could switch back and forth between menus all you wanted up to the time limit for the spell (30 seconds should be more than enough time for anyone unless its a huge number of menus). As for the ScriptEffectFinish, I am not exactly sure what you are trying to do with the Player.Cast Spell?
--ShadowDancer 19:35, 25 August 2007 (EDT)
I was trying to recast the spell on the player, in case the timer ran out. Otherwise, I have no idea what you're talking about :). I'll leave the spell part up to you, if you don't mind.
--Haama 22:19, 25 August 2007 (EDT)
OK, it would be an addition to the ScriptEffectUpdate block and look something like:
scn MenuVariablesScript

Short Choosing
Short Choice
Short DoOnce

Begin SpellEffectStart
  ;Whatever you want to do
  Set Choosing to -1
End

Begin SpellEffectUpdate

  If (Choosing == -1) ;Display your menu
    Messagebox "What do you want to do?", ["Button0"], ..., ["Button8"], "Next Page"
    Set Choosing to 1
    Set Choice to GetButtonPressed

  Elseif (Choosing == 1)
    If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
    Elseif (Choice == 0) ;Button0
      ;Whatever you want to do
      Set Choosing to 0
...
    Elseif (Choice == 8) ;Button8
      ;Whatever you want to do
      Set Choosing to 0
    Elseif (Choice == 9) ;Next Page
      Set Choosing to -2 ;Following menu (choosing == -2)
    Endif

  Elseif (Choosing == -2) ;Gold menu
    Messagebox "What do you want to do?", ["Button0"], ..., ["Button8"], "Exit"
    Set Choosing to 2
    Set Choice to GetButtonPressed

  Elseif (Choosing == 2)
    If (Choice == -1) ;No choice yet
      Set Choice to GetButtonPressed
    Elseif (Choice == 0) ;Button0
      ;Whatever you want to do
      set Choosing to 0
    ...
    Elseif (Choice == 8) ;Button8
      ;Whatever you want to do
      Set Choosing to 0
    Elseif (Choice == 9) ;Exit
      Set Choosing to 0 ;to close the menus
    Endif

  ElseIf (Choosing == 0)
    If (DoOnce == 0)
      PlayMagicShaderVisuals ;place effect shader Editor ID here i.e. effectEnchantMysticism
      Set DoOnce to 1
      Set Timer to 4
    ElseIf (Timer > 0)
      Set Timer to Timer - GetSecondsPassed
    ElseIf (Timer < 0)
      StopMagicShaderVisuals ;place effect shader Editor ID here i.e. effectEnchantMysticism
      Set Timer to 0
      Player.Dispel ;place spell's Editor ID using script here i.e. SplMenuVariables
    EndIf

  Endif

End

Begin ScriptEffectFinish
End
The things I would add are the italicized sections and just remove the ScriptEffectFinish block. Setting the Duration on the spell to 30 should give someone more than enough time to make a choice on a smaller menu and to even flip between menus. If the menus are more complex requiring more time, just raise the Duration of the spell to give them more time. Any change that clicking the button does can be done when the GetButtonPressed returns a value. The Dispel will get rid of the active spell and no worries about a spell hanging there doing nothing.
--ShadowDancer 23:25, 25 August 2007 (EDT)
Actually, I did get the multi-menu spell script working. See Raziel23x's script here for a working MessageBox with multiple menus. The only thing I didn't do were the things I said I would do if I were writing the script since I didn't know if he would want them. Additionally, using a single page menu works fine in the Alter Weather spell that I created, since I couldn't see a reason to write 7 different spells for each weather function in Tamriel, that I used for testing purposes for information for the Talk:ScriptEffectUpdate page. The original spell script I threw up was essentially a reduced version of what I did for Raziel23x's script.
--ShadowDancer 22:38, 25 August 2007 (EDT)


I found that a maximum duration of 10-15 seconds is more then enough time for a magic affect script. I have been testing durations for spell multi menus trying to find a medium for them and I found that with a 10-15 second Duration even after going through 3 menus plus 2 sub menus I have about 8 seconds left on the clock when I use the 10 seconds. I notice it takes about a half a second to get between the menues.
--Raziel23x 07:23, 26 August 2007 (EDT)

and you had an FPS of about 30, right? I never tested it, but I assume that it takes 15 frames, instead of 1/2 a second, to return the button press. So if the user was running around 15 FPS it would take 2x as long between menus, and they would take 14 seconds instead of 7. If you want to artificially lower your FPS to test it, use this script (OBSE)
short LoopNum
short LoopTotal

begin GameMode
  set LoopNum to 0
  Label 1
  if (LoopNum < LoopTotal)
    player.GetInventoryObject 0
    set LoopNum to (LoopNum + 1)
  endif
end
Put it in a quest script so you can change LoopTotal in game, until your FPS is around 15, or even lower, and try again.
--Haama 10:19, 26 August 2007 (EDT)

I also Found a way of doing this Since I figures out what I was doing wrong with the script Sorrow ShadowDancer I went a totally Different route with my script because after i finished compiling the script in notepad++ and went to copy and paste a test script into the CS I had to break my script up into units but still having them function as if they are one script when in actuality if you open up the plug-in in the construction set you will see that it is actually 36 separate scripts all linked with a main script that uses the Multi messagebox using the step system. Me and Kyoma over on the ES official Forums been playing around with different Ideas to do this as well. He devised a way with using invisible activators while I came up with a spell with in a spell which when you make a choice inside the multi messagebox to call the functions I wish to change Example: You click Assaults and you will get a sub menu that will ask you what do you want to set on Assaults and it will cast a spell that will call a messagebox that give you 9 options being -1 -10 -100 All +1 +10 +100 back and Quit. Back will make it go back to the main prompt IE the main script again to allow you to main another choice on the listings. I hated that I had to go this rout but when you have a script that just doing one option like messing with the Assaults list with just scripting the choices and using the formulas of resetting them or adding and taken away plus calling the right scripts takes up just a little over 200 lines and that is just one part of 34 ModPCMiscStat plus two for fame and infamy which is 36 options all together and each option has 9 sub menus which has there own calls and checks which are in place to keep the user from breaking something for example if something goes negative it will not just got to say if you by mistake went to -1 the code will compile it and set you to -240000 something So I placed safeguards to prevent this from happening in the first place and to warn the user of this and causing it to kill that function and go back to the choices menu allowing them to try again with one of the other options that might work.
--Raziel23x 07:42, 26 August 2007 (EDT)

I was under the assumption that ShadowDancer is Kyoma? So, that should be the same(ish) script that you both tried (not that they didn't work)?
Not quite the right place for it (no, that would be on an extra in the article...), but you can allow the player to choose any number by giving them the options "Cancel" "-10 (-12 to -8)" "-5 (-7 to -3)", "-2", "-1" "0"... and returning to the menu when the player selects the ranged numbers (or until they press 0 or cancel).
--Haama 10:28, 26 August 2007 (EDT)
No, I am not Kyoma. I believe that on the Official Elder Scroll Forums I am Shadow_Dancer if I recall correctly. No matter how you managed it, I am glad that you got your script working Raziel23x. I don't know whether using a Magic Effect script is better or not. I see no reason not to use one if I am scripting a spell that needs a menu for some reason. Honestly, it seems easier to include a menu for a magic effect in the spell script itself, but that is probably due to the different computer languages that I have learned. To me, short, simple, and functional is elegant.
--ShadowDancer 17:18, 26 August 2007 (EDT)
Sorry about that, then.
--Haama 18:37, 26 August 2007 (EDT)
I have not clue who is who where. No one has told me anything so I am like I said who is here is who on the ES official forums.
--Raziel23x 12:35, 26 August 2007 (EDT)

BTW who is James Joyce?

--Raziel23x 12:39, 26 August 2007 (EDT)
Wrote Ulysses, Finnigan's Wake - used Stream of Consciousness in his writing... sometimes for 200 pages. Your post was very Stream of Consciousness. BTW, did you see my reply to your first section?
--Haama 12:59, 26 August 2007 (EDT)

OK, as before, I haven't followed all of this. You guys write a lot.

My thoughts are this: If you want a spell to trigger a menu system, you have the spell set a variable and have the menu script in an activator. Same with tokens - if you need tokens to determine whether or not a menu should be displayed, have the tokens set variables on the activator and have the activator run the script. Tokens and spells add a ton of headaches, complexity, and possiblity for errors that are just completely unnecessary in every situation. Unless I am seriously missing something, there is no good reason to have the menu script actually within the spells or tokens. It's unnecessary and error-prone, and really is not any simpler.
Dragoon Wraith TALK 13:29, 26 August 2007 (EDT)

That was my thought when writing the tutorial. However, several people have asked for the other versions. With a good warning, and the other versions on other pages, I think it'll be ok.
--Haama 18:37, 26 August 2007 (EDT)
But why? I dunno, I feel like this is something where we should just be like "trust us, it's more of a headache than you want to deal with" - if you're skilled enough to handle that situation, you don't need this tutorial. People reading this are not prepared to manage that, methinks. Seriously, what purpose could having the menu script be in the spell's script serve? Two separate scripts keeps things organized, prevents a number of headaches, and best of all, this tutorial can offer a "one size fits all" answer.
I'm sorry that I'm harping on this, but I really feel like it only generates more, not less, confusion.
Dragoon Wraith TALK 00:14, 27 August 2007 (EDT)
Alright, new question. Are you assuming that the individual is trying to keep track of the variables that have been set?
--ShadowDancer 11:28, 27 August 2007 (EDT)
We're assuming that at least some people will want to store the variables.
Let's rephrase the question - I use activators all the time, so there may be downsides I've forgotten about - what are the downsides to using activators? I know they're a pain to move around, and more than likely you have to make sure they're out of an Oblivion cell in case it resets (a major one, but either it's rare or only a problem with container's inventories, etc.), any others? (we seem to have gone over the downsides of the others)
--Haama 13:30, 27 August 2007 (EDT)
Well with mine I am kinda of cheating since spell steps reset each time so i have a Dummy quest set up that all it is there for is to hold on to the Variables that I wish to keep permanent.
Example:
Your Script
if AADummyQuest.Step == 0
Blah
That way I can have multi spell scripts combined into one function but you can call me crazy if you like. Yea I know I have completely making this thing Extremely complex, But I I have always been for the one to think out side of the box and try something a different way. but that way the example above having a dummy quest that all it is for is for your to store your shorts longs and floats for the spell menu script to keep up with certain areas which you may wish to keep in case for example you do run out of time then you could have this set up to have the spell script to start back at where it left off when the spell expired before you was finished.
--Raziel23x 12:20, 27 August 2007 (EDT)
I haven't tried this, but I don't think it'll work so easily. I think the spell will only expire in GameMode, meaning it will only expire while trying to catch the player's response. Assuming that's true, then when you restart the spell either one of two things will happen - it'll catch a long forgotten option, or it won't catch anything and constantly loop 'GetButtonPressed' while it returns -1 (hence the recasting spell in the tutorial). Also, Raziel23x, what was your FPS when you tested the time between menus? From your results, I would expect 30 FPS? What happens if your FPS is slower? I'm trying to tell if the pause is based on frames (15 frames) or time (1/2 a second) - much thanks.
--Haama 13:30, 27 August 2007 (EDT)
I asked the above question because I wasn't assuming that you would be saving a variable. That lends a whole new dimension to what is being done in the menu system that is not even present in the title of the tutorial, which is probably why we have so much back and forth going on about ways to do multi-menus. I was just trying to include a multi-menu in a script concept to what I was assuming was a MessageBox multi-menu tutorial (hence why it seemed overly complicated). I would like to make the following suggestions:
  1. Move this page to a new title
  2. Use this title to show people how to create multi-menus in different instances (activator, spell, etc.)
  3. Link this page to the next as an advanced tutorial
This has a bonus of being able to pare down the advanced tutorial to something that can be used however they wish to implement it plus it gives the information on different ways to create multiple menus for those who don't want to save settings. I'll be back on later with ways that activators can be headaches.
--ShadowDancer 17:06, 27 August 2007 (EDT)
OK, now I'm very confused. Why would not want to store the results of a menu? Or, if you do, just drop the information, this would work just fine. ShadowDancer, I really don't understand what you want from this tutorial, and I really don't understand why you would want a MessageBox menu in anything but an Activator. What purpose does that serve? What is complicated about this script that you would remove? Yes, menu scripts are complicated, but that's what they are. I don't see how you can simplify it while still asking questions of the player and getting answers. Please explain what you mean, and please explain what possible situation might be better served by a menu in a spell than in an activator triggered by spell.
Dragoon Wraith TALK 18:17, 27 August 2007 (EDT)

(Back to the left) First off, let me say that I didn't do more than skim this tutorial originally since I was looking to help Raziel23x out with his spell script. It just so happens that this came into play at the same time that this tutorial was marked as possibly containing misinformation. Since Haama had written that he hadn't seen multiple menus done in a spell script, I added a spell script that worked multiple menus via the MessageBox function. Additionally, since I was working with Raziel23x's script, I went pretty much to the scripts to look at the coding being fairly competent with scripts. So yes, this whole mess is my fault. However, aside from that, what I am trying to say is that this isn't really a MessageBox tutorial, its a MessageBox Menu System and Variable Storage tutorial.

I suspect that if there had been a simplified version of how to set up multiple menus using the MessageBox function in a Magic Effect script that Raziel23x probably wouldn't have had to ask for help with it. I even had trouble looking through the scripts trying to seperate out what wasn't necessary and apply it to a spell script - the real problem ended up being an active return statement (If Choice == -1 ==> Return). To this end, I think that a Multi-Menu tutorial using MessageBox is probably something that would be useful with a demonstration of how to do it in different ways, i.e. Activators, Spells, etc. so that if someone needs help figuring out how to do it, they don't have to come to a tutorial that isn't set up for it just because its the closest thing that will help them. If you look at what Raziel23x was doing, it was either use a multiple menu or else write 20+ seperate spells. I personally would have done the same thing Raziel23x originally did; made multiple menus in a single spell. I did something similar with the Alter Weather spell that I made a while ago in that I allowed the caster to choose the weather type from a menu when the spell is cast rather than writing 7 seperate spells for each weather type in Tamriel. I didn't feel that the seperate weather types warranted 7 seperate spells when one spell could do all of them (it also cuts down on clutter in the spell list). The difference being that mine didn't need multiple menus for the spell where as Raziel23x's script did. This is where a menu in a spell serves better than an activator - because you don't need to drag the activator out and deal with it and then put it away again when just casting a simple spell. You just handle the choice and the consequences internally in the spell.

Likewise, there are other things that don't require variables to be stored when using multiple menus for different choices. To that end, I think it would be wise to show people how to just make multiple menus for what they wish to do. I also agree that there are times when one might want to store variables choosen from multiple menus. Hence my suggestions above. A tutorial to create multiple menus. Another tutorial (or the same one if you like, though it would be necessarily longer) to show how to take those multiple menu systems and store the variables. The current tutorial didn't show how to set up multiple menus just for the sake of creating multiple menus and demonstrate them before introducing the activator, and the information in the article didn't lend well to a spell script that needs a menu to make a choice about the spell being cast. Which is what I was originally trying to suggest - a menu in a spell that doesn't store variables - because I hadn't paid much attention to the tutorial other than that it talked about creating multiple menus.

--ShadowDancer 23:51, 27 August 2007 (EDT)

While I agree a piecemeal approach works (and is desirable) for most topics, I don't feel the same with messageboxes. Before I posted this tutorial, there were a couple of simple examples floating around (I think there was even a generator), that most would use as a base. While the scripts worked when things were kept simple, they didn't work once the script became more complex. There were quite a few threads and people asking for help, who had started out with the simple scripts, and, getting tired of pointing out the same 3 things, I wrote the tutorial - hoping that an all-purpose menu script would prevent people from running into the same errors whenever they want their menus to do something slightly different.
I see what you mean about the returns. I need to think about them for a bit, but I don't think they're needed.
Hmm... trying to write the spell advantages and disadvantages - 3 questions: Will a ScriptEffectStart work from MenuMode? Will the GameMode or MenuMode blocks run in a spell (and if so, how many times)? How often does the ScriptEffectUpdate run (from the discussion on that article, it seems like it's not every frame, at least I hope the test wasn't at 7 FPS)?
--Haama 12:19, 28 August 2007 (EDT)
Well, some of these I can answer right off the top of my head, and can make reasoned guesses at some others although they will need confirmation. ScriptEffectUpdate does not operate in MenuMode. MenuMode will put any normally written spell on hold - ScriptEffectStart, ScriptEffectUpdate, and ScriptEffectFinish all pause in MenuMode. ScriptEffectUpdate is somewhat odd and I am not exactly sure why. It is like GameMode and yet isn't like GameMode, at least thats how it appeared to be with effect shaders - I am not sure if that has to do with how the effect shaders work or not, since I have never tried running the same test with a GameMode block (no it wasn't at 7 FPS, it was more like 20ish). Yes, you can use a GameMode block in a spell script, and as far as I know, it acts like a regular normal GameMode block. Effect shaders should be tested with a GameMode block to see if the results turn out the same as they do in a ScriptEffectUpdate block; should probably be tested together in one script. I am not positive about the MenuMode block, but I am pretty sure that it will also run inside of a MagicEffect script - that will need testing to confirm. I believe that it is possible to cast a spell from a MenuMode block, but that it won't initialize until exiting MenuMode when written in standard format - also needs testing. I am off to start some of these tests.
--ShadowDancer 14:09, 28 August 2007 (EDT)
Well, some interesting results showed up. Some of my earlier information is apparently wrong. Using pretty much the same script as before, I got the following results:
Spell cast @ 20 FPS (was the easiest FPS to achieve multiple times)
0 Duration = 3 cycles
1 Duration = 18 cycles
2 Duration = 36 cycles
3 Duration = 56-58 cycles (which is a bump I noticed the first time testing this)
But the cycles are consistant up until you hit the Duration of 3. To my surprise, MenuMode will not work from a Magic Effect script. GameMode and ScriptEffectUpdate produce the same number of cycles inside of the script with approximately 18-20 FPS (according to ATI) while the effect shader is running (apparently its closer to 18 and increases as the effect shader continues longer than 2 seconds). Based on this latest test, it leads me to believe that the ScriptEffectUpdate runs when the ScriptEffectStart is initialized, runs once just for the ScriptEffectUpdate, and once when the ScriptEffectFinish is run at minimum duration (of 0). I am going to try a test now to determine if the ScriptEffectUpdate will run before the ScriptEffectStart if I place it above that in the script.
--ShadowDancer 15:26, 28 August 2007 (EDT)
Yes, those numbers make more sense. So ScriptEffectUpdate is every frame, or at least as often as GameMode (I kind-of wonder if the FPS shown is wrong, or if GameMode doesn't run every frame, but not too much)
--Haama 11:50, 29 August 2007 (EDT)
OK, this result is really weird. A MessageBox in a ScriptEffectUpdate before a GameMode block will stop the GameMode block from running at all with a zero duration (ScriptEffectUpdate still cycles 3 times though). If the GameMode block is first, it will run once with a zero duration and the spell will go through its full routine (with three passes through the ScriptEffectUpdate block). Once a non-zero duration is included, the GameMode count will be 1 less than the ScriptEffectUpdate count (regardless of script order).
If the GameMode block has the MessageBox (no MessageBox in the ScriptEffectUpdate block), it will cycle once, while the spell goes through the full spell at zero duration (including 3 ScriptEffectUpdate cycles). If there is a non-zero duration to the spell, the GameMode count will still be 1 less than the ScriptEffectUpdate count with the same script. Moving the GameMode block to before or after the ScriptEffectUpdate block has no effect in this case (zero or non-zero duration).
The ScriptEffectUpdate block will run before the ScriptEffectStart block when placed before it in the script. Apparently this block runs whenever the script is cycled, no matter where it is placed.

Base Script:

Scriptname SCTrialEffect

Short SEUCount
Short GMCount

Begin ScriptEffectStart
  Player.PlayMagicShaderVisuals effectAtronachFlame
  Message "Spell Started"
End

Begin ScriptEffectUpdate
  Set SEUCount to SEUCount + 1
End

Begin GameMode
  Set GMCount to GMCount + 1
  If GMCount == 1
    MessageBox "Count = 1"
  EndIf
End

Begin ScriptEffectFinish
  Player.StopMagicShaderVisuals effectAtronachFlame
  MessageBox "ScriptEffectUpdate Count = %3.0f <br> GameMode Count = %3.0f", SEUCount, GMCount
End
--ShadowDancer 16:32, 28 August 2007 (EDT)
I wonder what happens if you use printc instead of messagebox? Will the message be displayed once, or multiple times?
--Haama 11:50, 29 August 2007 (EDT)
A spell can be cast while in MenuMode from a MenuMode script. It doesn't start the Magic Effect script until the player has exited MenuMode. Even a zero duration spell won't start running until back in GameMode.
--ShadowDancer 03:29, 29 August 2007 (EDT)

Ok, so if I understand this correctly, there's no way for the spell to start in MenuMode. I've noticed from Guidobot's Throwing Stars 3 that a MenuMode block will run from a magic script (at least for potions), but he said it will only run for a single frame.

Ok, so that also means that spell menus can only be used from GameMode (not bad, but it's still a point). This also means that there will always be passing time between menus, so the spell must be recast if time runs out.

--Haama 11:50, 29 August 2007 (EDT)


Haama, out of curiosity, why do you have so many

   If (Choice == -1) ;No choice yet
     Set Choice to GetButtonPressed

statements in the script? If you use a couple more If statements, you could just put one of those in and remove that If statement from each of the additional menu sections. I don't even think you need to use an If statement with GetButtonPressed to begin with.

--ShadowDancer 05:59, 29 August 2007 (EDT)

See MessageBox_Tutorial#Running_the_same_choice_for_multiple_frames. It's rare, but I've needed to do it, and I've had to answer a couple of threads on it.
--Haama 11:50, 29 August 2007 (EDT)
Lots of rewrites. It should be much easier to understand the original cases and reasons for each part of the script now. I've also left a much clearer place to place alternatives (spells, token scripts, quest scripts, etc.).
Since no one has brought up problems with the Poison Equipper mod, I'll switch over to using SetAtStart rather than moving the activator back to the XMarker. I'll give that a little while longer, but so far so good.
--Haama 13:03, 29 August 2007 (EDT)

Missing statement in examples[edit source]

All examples used to illustrate an activator menu (section 4.5 and following) are missing a Return statement:

If Working
  If (Choosing == 0)
    ....
    Set Working to 0
    ....
    Return
  Elseif (Choosing == -1)
    ....
  Elseif (Choosing == 1)
    ....
  Elseif (Choosing == -10)
    ....
  Elseif (Choosing == 10)
  ...
  Endif
  Set Working to 1
Endif

Otherwise, setting Choosing to 0 will NOT provide for Working to be reset to 0 at the end of the script, since Working will anyways get set back to 1 after the if block.

No Return statement would imply that after a first activation (menu use), Working stays set to 1, and a bunch of "if-elseif" will from then on get evaluated in GameMode block, while not using the Activator. Or, it will continuously check for Choosing == 0, set Working to 0 and then reset Working to 1... I wonder what would happen if this activator is then moved back to a remote cell, to see if the engine would make its script keep on going into ModeBlocks (since a set variable instruction within the first if block will always fires up the script for he next frame... But I guess that the activator would have to get activated in its remote cell via an Activate player,1 instruction for the later to take place - when the activator is unloaded, the end of script keeps Working set to 1... I dunno). --HawkFest 11:16, 24 December 2007 (EST)


Thanks Hawkfest. (I think) I've fixed them all, even the ones on the sub-pages. Instead of the return, I moved the set Working to 1 line up top, so it can be set to 0 below. (Oops, thought I had fixed that long ago)--Haama 11:12, 24 December 2007 (EST)
I can see that you too you don't like Return statements too much..;p --HawkFest 11:26, 24 December 2007 (EST)