Rizalgar Posted December 7, 2018 Share Posted December 7, 2018 Ok, basically I'm writing a script to open a MessageBox that opens up more MessageBox's, each with their own summon. I've got the multiple boxes working, the problem is, regardless of which MessageBox I'm in, the selection always acts like it's from Box one. I can provide a quick video if needed to show what I mean. Meanwhile, here's the script. I think, maybe I have to have all the dialogue boxes pre-written in stages, then have all the answers in stages afterwards? I'm not sure. ||||||||||||||||||||||||||||||||||||||||///////////////\\\\\\\\\\\\||||||||||||||||||||||||||||||||||| Begin _trainingactivator Short ScriptStateShort Button If ( MenuMode == 1 )ReturnEndIf If ( OnActivate == 1 )If ( ScriptState == 0 )MessageBox "What would you like to summon?" "Scrib - Level 1 | 20 Gold" "Rat - Level 2 | 35 Gold" "Kwama Warrior - Level 3 | 45 Gold" "Bonewalker - Level 4 | 70 Gold" "Scamp - Level 5 | 75 Gold" "Next"Set ScriptState to 0EndIfEndIf If ( ScriptState == 0 )Set Button to GetButtonPressedIf ( Button == 0 )If ( Player->GetItemCount Gold_001 < 20 )MessageBox "You don't have enough gold"ElsePlayer->RemoveItem "Gold_001" 20MessageBox "You summon a level 1 Scrib."PlaceAtPC "scrib", 1, 128, 3Set ScriptState to 1EndIfEndIfIf ( Button == 1 )If ( Player->GetItemCount Gold_001 < 35 )MessageBox"You don't have enough gold."ElsePlayer->RemoveItem "Gold_001" 35MessageBox "You summon a level 2 Rat."PlaceAtPC "Rat", 1, 128, 3Set ScriptState to 1EndIfEndIfIf ( Button == 2 )If ( Player->GetItemCount Gold_001 < 45 )MessageBox "You don't have enough gold."ElsePlayer->RemoveItem "Gold_001" 45MessageBox "You summon a level 3 Kwama Warrior"PlaceAtPC "kwama warrior", 1, 128, 3Set ScriptState to 1EndIfEndIfIf ( Button == 3 )If ( Player->GetItemCount Gold_001 < 70 )MessageBox "You don't have enough gold."ElsePlayer->RemoveItem "Gold_001" 70MessageBox "You summon a level 4 Bonewalker."PlaceAtPC "bonewalker", 1, 128, 3Set ScriptState to 1EndIfEndIfIf ( Button == 4 )If ( Player->GetItemCount Gold_001 < 75 )MessageBox "You don't have enough gold."ElsePlayer->RemoveItem "Gold_001" 75MessageBox "You summon a level 5 Scamp."PlaceAtPC "scamp", 1, 128, 3Set ScriptState to 1EndIfEndIfIf ( Button == 5 )Set ScriptState to 3EndIfEndIf If ( ScriptState == 3 )Set Button to GetButtonPressedMessageBox "Levels Six through Ten" "Shalk - Level 6 | 60 Gold" "Skeleton Warrior - Level 7 | 110 Gold"If ( Button == 6 )If (Player->GetItemCount Gold_001 < 60 )MessageBox "You don't have enough gold."ElsePlayer->RemoveItem "Gold_001" 60MessageBox "You summon a level 6 Shalk."PlaceAtPc "shalk", 1, 128, 3Set ScriptState to 3EndIfEndIfIf ( Button == 7 )If ( Player->GetItemCount Gold_001 < 110 )MessageBox "You don't have enough gold."ElsePlayer->RemoveItem "Gold_001" 110MessageBox "You summon a level 7 Skeleton Warrior"PlaceAtPC "skeleton warrior", 1, 128, 3Set ScriptState to 3EndIfEndIfEndIf If ( ScriptState == 1 )Set ScriptState to 0EndIf If ( ScriptState == 3 )Set ScriptState to 0EndIf End _trainingactivator Please Note, it's not complete. No point completing it yet if I can't get it working. Link to comment Share on other sites More sharing options...
Rizalgar Posted December 7, 2018 Author Share Posted December 7, 2018 In the second box, buttons 6 and 7 are there because I tried using 0 and 1 and it wouldn't work, forgot to change them back before posting. Link to comment Share on other sites More sharing options...
Rizalgar Posted December 7, 2018 Author Share Posted December 7, 2018 https://youtu.be/hRVSa-JGaJk Video showing what the problem is Link to comment Share on other sites More sharing options...
Rizalgar Posted December 7, 2018 Author Share Posted December 7, 2018 (edited) Okay now I came across something strange. Any time I use Button 1, regardless of the activator, it summons a Scrib. I broke the game apparently. I am doing this in OpenMW with the OpenMW Editor, if that makes any difference. Edited December 7, 2018 by Rizalgar Link to comment Share on other sites More sharing options...
cyran0 Posted December 7, 2018 Share Posted December 7, 2018 (edited) Please indent your code to make your script easier to read and understand. I suspect if you select a skeleton warrior it will summon a rat. This is because after each cycle your script runs (and it runs to the end each cycle) you will set the script state to 0 if it is 1 or 3. After the second menu displays and the player makes a choice that choice is applied to the first menu block. You need an early return while the script waits for the player to make a choice. Such returns will improve the efficience of your code as well. After activation you want to set 'ScriptState' to 1 (not 0 as it already is) to prevent the player from activating it a second time before the choice is completed. As a personal choice, there is no need for the message informing the player that creature is summoned, and specifying the level of the summon is immersion-breaking. Rather than try to explain where changes should be made I offer the following untested code: Begin TrainingActivator ; Underscores as the first character of names can be a dangerous practice short scriptState short button if ( menumode == 1 ) return endIf if ( OnActivate == 1 ) if ( scriptState == 0 ) messagebox "What would you like to summon?" "Scrib (20 gold)" "Rat (35 gold)" "Kwama Warrior (45 gold)" "Bonewalker (70 gold)" "Scamp (75 gold)" "Next" set scriptState to 1 endIf endIf if ( scriptState == 1 ) set button to GetButtonPressed if ( button == -1 ) ; the player has not made a choice yet return elseif ( button == 0 ) ; scrib if ( ( player->GetItemCount "Gold_001" ) < 20 ) messagebox "You don't have enough gold." else player->RemoveItem "Gold_001" 20 PlaceAtPC "scrib" 1 128 3 endIf elseif ( button == 1 ) ; rat if ( ( player->GetItemCount "Gold_001" ) < 35 ) messagebox "You don't have enough gold." else player->RemoveItem "Gold_001" 35 PlaceAtPC "rat" 1 128 3 endIf elseif ( button == 2 ) ; kwama warrior - perhaps you meant kwama forager? if ( ( player->GetItemCount "Gold_001" ) < 45 ) messagebox "You don't have enough gold." else player->RemoveItem "Gold_001" 45 PlaceAtPC "kwama warrior" 1 128 3 endIf elseif ( button == 3 ) ; bonewalker - another comparatively high level challenge if ( ( player->GetItemCount "Gold_001" ) < 70 ) messagebox "You don't have enough gold." else player->RemoveItem "Gold_001" 70 PlaceAtPC "bonewalker" 1 128 3 endIf elseif ( button == 4 ) ; scamp - more like it if ( ( player->GetItemCount "Gold_001" ) < 75 ) messagebox "You don't have enough gold." else player->RemoveItem "Gold_001" 75 PlaceAtPC "scamp" 1 128 3 endIf elseif ( button == 5 ) ; next menu branch set scriptState to 2 endif endif if ( scriptState == 2 ) ; second menu branch messagebox "Shalk (60 gold)" "Skeleton Warrior (110 Gold)" "Next" set scriptState to 3 endif if ( scriptState == 3 ) set button to GetButtonPressed if ( button == -1 ) ; the player has not made a choice yet return elseif ( button == 0 ) ; this is first choice on new menu branch - shalk if ( ( player->GetItemCount "Gold_001" ) < 60 ) messagebox "You don't have enough gold." else player->RemoveItem "Gold_001" 60 PlaceAtPC "shalk" 1 128 3 endIf elseif ( button == 1 ) ; skeleton warrior if ( ( player->GetItemCount "Gold_001" ) < 110 ) messagebox "You don't have enough gold." else player->RemoveItem "Gold_001" 110 PlaceAtPC "skeleton warrior" 1 128 3 endif elseif ( button == 2 ) ; next menu branch - just for illustration set scriptState to 4 endif endif if ( scriptState == 4 ) ; third menu branch messagebox "Fargoth (1000 gold)" set scriptState to 5 endif if ( scriptState == 5 ) set button to GetButtonPressed if ( button == -1 ) ; the player has not made a choice yet return elseif ( button == 0 ) ; you get the idea endIf endIf set scriptState to 0 ; the script does not reach this point until the player makes a choice End TrainingActivator Tightening up the first message (choice menu) makes it possible to include more creatures per menu branch. This is expensive training. While it may not be necessary, I uncoupled each menu branch into separate logical blocks. There is an 'instruction limit' for an if-block. Depending on how many choices you plan to offer it is possible the code would have exceeded it. Edited December 7, 2018 by cyran0 Link to comment Share on other sites More sharing options...
Rizalgar Posted December 8, 2018 Author Share Posted December 8, 2018 (edited) Okay, I'll remember that next time. Thanks for the help. However, now the script will indeed spawn from the proper message box, but it will not go away, until you make a second selection, which defaults back to the first box. So say you choose Skeleton from box Two, the menu will remain and if you press Two again, it will summon a rat. I have tried moving around the If ( Button == -1 ) to see if it would remedy it, but to no avail. Any ideas? Edit -- Is it maybe because the script is defaulting back to a certain ScriptState? I will tinker around with the variables a little bit and see what happens. Edited December 8, 2018 by Rizalgar Link to comment Share on other sites More sharing options...
cyran0 Posted December 8, 2018 Share Posted December 8, 2018 I tested the script myself in-game. I did make an error in the second and third branches of the message tree - I forgot the prompt "What would you like to summon?" so the first choice became the prompt. Other than that, the script worked as expected for me. I do suggest that you add an option for the player to cancel the training on each branch. I cannot account for why the original messagebox is not clearing for you after you make your first choice. Link to comment Share on other sites More sharing options...
Rizalgar Posted December 9, 2018 Author Share Posted December 9, 2018 Ok, I'll rewrite the script based off of yours and see what happens. Thanks for testing it for me :). I just really wanted to try writing it myself from scratch but oh well Link to comment Share on other sites More sharing options...
Rizalgar Posted December 9, 2018 Author Share Posted December 9, 2018 Can confirm, works as intended. However, OpenMW is a different story. I guess it uses a different script structure. The OpenMW CS isn't reporting any errors though. Oh well Link to comment Share on other sites More sharing options...
Rizalgar Posted December 9, 2018 Author Share Posted December 9, 2018 I stand corrected. I didn't have the omwaddon loaded. Derp-o-matic 9000 Link to comment Share on other sites More sharing options...
Recommended Posts