New scripting question...

Post » Fri Jun 17, 2011 11:05 pm

So my script works very simply. I have a few different equipable items, however you only get one. Upon equipping said item, a menu pops up asking you to pick a color for the item. Then it goes ahead and equips the item of the given color. Easy enough, I got this to work, however the script is long and I would like ton condense it. so its easier to manipulate.

Ze script!
SCN EchoCazadorWingsScriptShort ButtonShort Menu1Short Menu2; Color Options: Menu #1; 0 = Red; 1 = Orange; 2 = Yellow; 3 = Lime; 4 = BlueGreen; 5 = Blue; 6 = Purple; 7 = Pink; 8 = Next Menu; 9 = Close Menu; Color Options: Menu #2; 0 = White; 1 = x; 2 = x; 3 = x; 4 = x; 5 = x; 6 = x; 7 = x; 8 = Previous Menu; 9 = Close MenuBegin OnEquip			ShowMessage EchoCazadorColorMENU01	Set Menu1 To 1EndBegin GameMode			If Menu1 == 1 ;Menu 1					Player.UnequipItem EchoCazadorWingsRed 0 1		Player.UnequipItem EchoCazadorWingsOrange 0 1		Player.UnequipItem EchoCazadorWingsYellow 0 1		Player.UnequipItem EchoCazadorWingsLime 0 1		Player.UnequipItem EchoCazadorWingsBlueGreen 0 1		Player.UnequipItem EchoCazadorWingsBlue 0 1		Player.UnequipItem EchoCazadorWingsPurple 0 1		Player.UnequipItem EchoCazadorWingsPink 0 1		Player.UnequipItem EchoCazadorWingsWhite 0 1		Player.RemoveItem EchoCazadorWingsRed 1 1		Player.RemoveItem EchoCazadorWingsOrange 1 1		Player.RemoveItem EchoCazadorWingsYellow 1 1		Player.RemoveItem EchoCazadorWingsLime 1 1		Player.RemoveItem EchoCazadorWingsBlueGreen 1 1		Player.RemoveItem EchoCazadorWingsBlue 1 1		Player.RemoveItem EchoCazadorWingsPurple 1 1		Player.RemoveItem EchoCazadorWingsPink 1 1		Player.RemoveItem EchoCazadorWingsWhite 1 1			Set Button To getButtonPressed			If Button == -1				Return			ElseIf Button == 0				Player.Additem EchoCazadorWingsRed 1 1				Player.EquipItem EchoCazadorWingsRed  0 1			ElseIf Button == 1				Player.Additem EchoCazadorWingsOrange 1 1				Player.EquipItem EchoCazadorWingsOrange 0 1			ElseIf Button == 2				Player.Additem EchoCazadorWingsYellow 1 1				Player.EquipItem EchoCazadorWingsYellow 0 1			ElseIf Button == 3				Player.Additem EchoCazadorWingsLime 1 1				Player.EquipItem EchoCazadorWingsLime 0 1			ElseIf Button == 4				Player.Additem EchoCazadorWingsBlueGreen 1 1				Player.EquipItem EchoCazadorWingsBlueGreen 0 1			ElseIf Button == 5				Player.Additem EchoCazadorWingsBlue 1 1				Player.EquipItem EchoCazadorWingsBlue 0 1			ElseIf Button == 6				Player.Additem EchoCazadorWingsPurple 1 1				Player.EquipItem EchoCazadorWingsPurple 0 1			ElseIf Button == 7				Player.Additem EchoCazadorWingsPink 1 1				Player.EquipItem EchoCazadorWingsPink 0 1			ElseIf Button == 8				ShowMessage EchoCazadorColorMENU02				Set Menu1 To 0				Set Menu2 To 1			ElseIf Button == 9				Return						Endif	Endif		If Menu2 == 1 ;Menu 2		Set Button To getButtonPressed			If Button == -1				Return			ElseIf Button == 0				Player.Additem EchoCazadorWingsWhite 1 1				Player.EquipItem EchoCazadorWingsWhite 0 1			ElseIf Button == 1				;Do Nothing			ElseIf Button == 2				;Do Nothing			ElseIf Button == 3				;Do Nothing			ElseIf Button == 4				;Do Nothing			ElseIf Button == 5				;Do Nothing			ElseIf Button == 6				;Do Nothing			ElseIf Button == 7				;Do Nothing			ElseIf Button == 8				ShowMessage EchoCazadorColorMENU01				Set Menu2 To 0				Set Menu1 To 1			ElseIf Button == 9				Return						Endif	EndifEnd


Now I know what I have posted wont work. As you can see by the large chunk of item unequipping and removal, the item is removed before the script can finish so the game crashes. As it stand, the only way I can get the script to work would be to have that long chunk copied into the "If" block for every option. That is bulky and annoying. So Im looking for a way to have a single section to run that bit of code and not crash... ideally.

Any suggestions?
User avatar
Quick Draw
 
Posts: 3423
Joined: Sun Sep 30, 2007 4:56 am

Post » Fri Jun 17, 2011 4:14 pm

Essentially, you'll want to put all of the UnequipItem/RemoveItem into a single if block. If you had many more different functions used on each reference, I would suggest using an NVSE Label/Goto loop with a counter to perform the functions on a reference variable. That shouldn't really be necessary with 2 edits each, though.

Spoiler
Begin GameMode			If Menu1 == 1 ;Menu 1		Set Button To getButtonPressed		If Button >= 0 && Button <= 7			Player.UnequipItem EchoCazadorWingsRed 0 1			Player.RemoveItem EchoCazadorWingsRed 1 1			Player.UnequipItem EchoCazadorWingsOrange 0 1			Player.RemoveItem EchoCazadorWingsOrange 1 1			[continue...]			Endif		Endif		If Button == -1			Return		ElseIf Button == 0			Player.Additem EchoCazadorWingsRed 1 1			Player.EquipItem EchoCazadorWingsRed  0 1		[continue...]		Endif	EndifEnd

User avatar
Nicole M
 
Posts: 3501
Joined: Thu Jun 15, 2006 6:31 am

Post » Sat Jun 18, 2011 8:35 am

To Unequip the wings:
If all the wings take a particular slot, you can equip then unequip an invisible item that uses that slot.

To remove them:
Player.RemoveItem MyCazadoreWingFormList 99 1


Where MyCazadoreWingFormList is a list of your wing objects.
User avatar
Chavala
 
Posts: 3355
Joined: Sun Jun 25, 2006 5:28 am

Post » Sat Jun 18, 2011 4:54 am

Im confused as to what checking of buttons will do. The problem comes with my blanked "Remove every possible item this script could add" and that is what causes the crashing because now the item with the script (Every item has a copy of the script attached to it) is no longer there to run.
User avatar
Harry Hearing
 
Posts: 3366
Joined: Sun Jul 22, 2007 6:19 am

Post » Fri Jun 17, 2011 7:40 pm

Im confused as to what checking of buttons will do. The problem comes with my blanked "Remove every possible item this script could add" and that is what causes the crashing because now the item with the script (Every item has a copy of the script attached to it) is no longer there to run.

Oh, I misunderstood what you were asking for. You should be able to simply call RemoveMe after a new set of wings is chosen and equipped.

Spoiler
Begin GameMode			If Menu1 == 1 ;Menu 1		Set Button To getButtonPressed		If Button == -1			Return		ElseIf Button == 0			Player.Additem EchoCazadorWingsRed 1 1			Player.EquipItem EchoCazadorWingsRed  0 1		[continue...]		Endif		If Button >= 0 && Button <= 7			RemoveMe		Endif	EndifEnd

User avatar
Scared humanity
 
Posts: 3470
Joined: Tue Oct 16, 2007 3:41 am

Post » Fri Jun 17, 2011 9:38 pm

To Unequip the wings:
If all the wings take a particular slot, you can equip then unequip an invisible item that uses that slot.

To remove them:
Player.RemoveItem MyCazadoreWingFormList 99 1


Where MyCazadoreWingFormList is a list of your wing objects.

This proved very useful. Replacing over 20 lines with 4


Oh, I misunderstood what you were asking for. You should be able to simply call RemoveMe after a new set of wings is chosen and equipped.

Spoiler
Begin GameMode			If Menu1 == 1 ;Menu 1		Set Button To getButtonPressed		If Button == -1			Return		ElseIf Button == 0			Player.Additem EchoCazadorWingsRed 1 1			Player.EquipItem EchoCazadorWingsRed  0 1		[continue...]		Endif		If Button >= 0 && Button <= 7			RemoveMe		Endif	EndifEnd


Call me inept or something but I'm still confused by this. Perhaps its just my difficulty understanding coding logic


Either way I want to thank you both for your help.
User avatar
ashleigh bryden
 
Posts: 3446
Joined: Thu Jun 29, 2006 5:43 am


Return to Fallout: New Vegas