WARNING: There's a character limit on scripts!

Post » Wed Jun 02, 2010 7:49 am

I've just discovered, to my tremendous dismay, that there's a character limit on scripts. Somewhere around line 1000, it started refusing to allow any more code. I know not many people will be tripped up by this, but for me, it puts me weeks behind schedule; I'll have to rethink a lot of my code, as I'm going to need several thousand lines at a minimum.

Just figured I'd warn any other scripters out there.

One thought - I wonder if this limit is a GECK editor limit, or something required by the engine... Maybe I can use an external tool to force it to the lengths I need.
User avatar
Dewayne Quattlebaum
 
Posts: 3529
Joined: Thu Aug 30, 2007 12:29 pm

Post » Wed Jun 02, 2010 2:04 pm

I've just discovered, to my tremendous dismay, that there's a character limit on scripts. Somewhere around line 1000, it started refusing to allow any more code. I know not many people will be tripped up by this, but for me, it puts me weeks behind schedule; I'll have to rethink a lot of my code, as I'm going to need several thousand lines at a minimum.

Just figured I'd warn any other scripters out there.

One thought - I wonder if this limit is a GECK editor limit, or something required by the engine... Maybe I can use an external tool to force it to the lengths I need.


This falls under common knowledge... There are ways of extending the allowed char limit as well.
User avatar
Kit Marsden
 
Posts: 3467
Joined: Thu Jul 19, 2007 2:19 pm

Post » Wed Jun 02, 2010 11:58 am

The character limit is about 33.000. Most likely, any script with that much code should be able to be simplified and/or condensed via *shortening of variable names, optimization, parenthesis/commenting removal, etc. but you can always split the script up into smaller chunks if you still can't squeeze it all into one.

*search/replace is a godsend for this

http://www.javascriptkit.com/script/script2/charcount.shtml
User avatar
remi lasisi
 
Posts: 3307
Joined: Sun Jul 02, 2006 2:26 pm

Post » Wed Jun 02, 2010 9:20 am

Thousands of lines in a single script? What are you trying to accomplish?
User avatar
joeK
 
Posts: 3370
Joined: Tue Jul 10, 2007 10:22 am

Post » Wed Jun 02, 2010 10:16 pm

Yeah, if you're writing thousands of lines you're almost certainly doing something wrong. If it's just scores of if(GetItemCount FoodItemA) elseif... you should just use NVSE and loop through a formlist- it's more easily expandable, and will condense hundreds of ifs into a single if(getItemCount ListItemVar) and half a dozen lines of loop structure.
User avatar
Aaron Clark
 
Posts: 3439
Joined: Fri Oct 26, 2007 2:23 pm

Post » Wed Jun 02, 2010 8:38 am

It's a large, stat-based town building/management mod. It includes twelve possible rooms, each upgradable to five different levels and three (each) unique end-of-tier expansions. It has several hundred random events that occur based on the stats of your constructed buildings. It has multiple specific non-room upgrades to the area, with visual and other bonus effects.

This one script is essentially just a series of hundreds of ShowMessage calls and GetButtonPressed checks. Even if I strip out comments - which I'm not going to do, as without them this mess becomes unmanageable - it's still way too small for my needs. I _can_ split it, I suppose, and unless I come up with some other solution, I'll have to - but it's going to take an unwieldy mass and make it even harder to handle. :(

I don't want to make the mod require NVSE. It severely limits its audience, and nothing I'm doing needs its functionality.

SaidenStorm - could please you point me in the direction of said ways to extend the limit? My searches have turned up nothing.
User avatar
asako
 
Posts: 3296
Joined: Wed Oct 04, 2006 7:16 am

Post » Wed Jun 02, 2010 5:52 pm

This one script is essentially just a series of hundreds of ShowMessage calls and GetButtonPressed checks.

So, you've basically packed multiple menus in one script.

You could try splitting them. For example, make a quest or several quests where each stage would show one message box, then call GetButtonPressed, check result and take appropriate action. The main quest would only need to store current stage number and call SetStage every frame while a menu is displayed. Communication between these stage scripts and the quest script would take a while to organize but it's not really hard. There is a limit of 255 stages per quest, but that can be solved by having more than one quest.

If you don't want to do that, you could simply split your menu into several independent menus and make several independent quests to control them.

Anyway, even if you bypass the character limit, you may hit some other limit. Maybe you'll have more commands in one script than the engine can handle. And I doubt the game will inform you about something like this, it may well just crash or some data may get corrupted. So before you try to bypass the character limit, you really should think about splitting your script up.
User avatar
ZzZz
 
Posts: 3396
Joined: Sat Jul 08, 2006 9:56 pm

Post » Wed Jun 02, 2010 7:48 am

This one script is essentially just a series of hundreds of ShowMessage calls and GetButtonPressed checks.
Infinimenu Template might help...
Spoiler
scn InfinimenuOptionsTokenSCPTInt iMessageInt iButtonBegin OnAdd	Set iMessage to -1	DisablePlayerControls 1 1 0 0 1 0 0EndBegin GameMode	If (iMessage > 0)		Set iButton to GetButtonPressed		If (iButton == -1)			Return		Else			Set iMessage to (iMessage * -1)			If (iMessage == -1)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 8) ; More					Set iMessage to -2				ElseIf (iButton == 9) ; Done					EnablePlayerControls 1 1 0 0 1 0 0					RemoveMe				EndIf			ElseIf (iMessage == -2)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; More					Set iMessage to -3 				ElseIf (iButton == 9) ; Back					Set iMessage to -1				EndIf			ElseIf (iMessage == -3)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; More					Set iMessage to -4 				ElseIf (iButton == 9) ; Back					Set iMessage to -2				EndIf			ElseIf (iMessage == -4)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; More					Set iMessage to -5 				ElseIf (iButton == 9) ; Back					Set iMessage to -3				EndIf			ElseIf (iMessage == -5)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; More					Set iMessage to -6 				ElseIf (iButton == 9) ; Back					Set iMessage to -4				EndIf			ElseIf (iMessage == -6)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; More					Set iMessage to -7 				ElseIf (iButton == 9) ; Back					Set iMessage to -5				EndIf			ElseIf (iMessage == -7)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; More					Set iMessage to -8 				ElseIf (iButton == 9) ; Back					Set iMessage to -6				EndIf			ElseIf (iMessage == -8)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; More					Set iMessage to -9 				ElseIf (iButton == 9) ; Back					Set iMessage to -7				EndIf			ElseIf (iMessage == -9)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; More					Set iMessage to -10 				ElseIf (iButton == 9) ; Back					Set iMessage to -8				EndIf			ElseIf (iMessage == -10)				If (iButton == 0)				ElseIf (iButton == 1)				ElseIf (iButton == 2)				ElseIf (iButton == 3)				ElseIf (iButton == 4)				ElseIf (iButton == 5)				ElseIf (iButton == 6)				ElseIf (iButton == 7)				ElseIf (iButton == 8) ; Back					Set iMessage to -9				ElseIf (iButton == 9) ; Done					EnablePlayerControls 1 1 0 0 1 0 0					RemoveMe				EndIf			EndIf		EndIf	Else;If (iMessage < 0)		Set iMessage to (iMessage * -1)		If (iMessage == 1)			ShowMessage Options01MESG		ElseIf (iMessage == 2)			ShowMessage Options02MESG		ElseIf (iMessage == 3)			ShowMessage Options03MESG		ElseIf (iMessage == 4)			ShowMessage Options04MESG		ElseIf (iMessage == 5)			ShowMessage Options05MESG		ElseIf (iMessage == 6)			ShowMessage Options06MESG		ElseIf (iMessage == 7)			ShowMessage Options07MESG		ElseIf (iMessage == 8)			ShowMessage Options08MESG		ElseIf (iMessage == 9)			ShowMessage Options09MESG		ElseIf (iMessage == 10)			ShowMessage Options10MESG		EndIf	EndIfEnd
... and can be added to until the character max is hit calling GetButtonPressed only once. Granted, it's set up for a token menu, but the code works for quest options menus too. You could have a 'If iMessage/Else' section up top with all the non-menu code. I'd bet, if you posted your script, some here would be able to offer ways of simplifying/condensing it that it will all fit for you.
User avatar
Blessed DIVA
 
Posts: 3408
Joined: Thu Jul 13, 2006 12:09 am

Post » Wed Jun 02, 2010 11:15 am

Considering yours needs I would switch to using Terminals as they can be sub linked infinitely and require very little scripting, just result scripts basically.
User avatar
Shae Munro
 
Posts: 3443
Joined: Fri Feb 23, 2007 11:32 am

Post » Wed Jun 02, 2010 7:22 pm

Re: Mumbojumbo

My worry with splitting up the menu - on top of, of course, it being a huge pain in the ass and making the code harder to edit - is largely one of race conditions failing. I'm worried about detecting menu states in multiple gameMode scripts simultaneously in subsequent frames and having that fail. I can make it work by adding more state variables, and indeed, that's probably what I'm going to do - i.e. I'm checking for menus 100-150 in one gameMode, 151-200 in another, etc. - but I'm not a huge fan of it. Really, I was hoping someone had a technical fix, but the more I think about it the more I realize you're right, and that's not going to happen - even if I could shove a textual script into the esp, in order for the geck to function it needs to be able to compile it.

As for the quest system, I'm loathe to work with it if I don't absolutely have to. The MessageBox system has a simplistic elegance of its own, and this thing is hard enough to keep straight in my head as-is.

Re: JustinOther

Thanks, but if I'm reading that script right, that's pretty much the system I'm working with. Check an "isMsg" variable once per gameMode, remember which menu is up with a "whichMsg" variable (they should be the same variable; I realized that later and will fix it soon), if/elseif to the right whichMsg, check btnPress, move to the right subsequent menu.

Re: SaidenStorm

Terminals was my first plan, and indeed, a large part of this will be handled via a massive nested terminal system. Does anyone know the maximum number of conditional line-items a terminal can have? I need... Upwards of 300, I think. I know it doesn't scroll; only a max of 5 should show at once.

The reason I can't use terminals for this part of the code is so simple it's maddening: it's a stat-based system. I.e. "your town has X defense points and Y resource points, what would you like to build in room Z?" And terminals can't display the values of variables like showMessages can. Of course, the flip side of that is that showMessages can only have 10 conditional responses per message, because a one-stop shop for player communication was just too easy, and Bethesda hates me. :P

*sigh* This wasn't even supposed to be the hard part. Converting a bunch of statics and movable statics into activators that move to a specific room on command was what I was putting off. >.<

If anyone is curious, here's a paste of the script. It's very unfinished, mind you, and ugly in places. I don't think there's really a viable option to shrink it, since the final one will need to be 10x this size and I'll have to split it anyway. And I'm not dumping comments; that way madness lies. I post it mainly as an intellectual curiosity for those who want to see how a character limit can make a grown man cry.

Spoiler
scn a450StatCheckint townSize ; Numerical calculation of town sizeint isMsg ; 0 = no message, 1 = message showingint btnPress ; Used to getPressedButton for last messageint whichMsg ; corresponds to "m###" in messages, indicates which messsage is upint lastMsg ; corresponds to "m###" messages like whichMsg, however this is used when a message is going to be called that might have multiple destinations for "return"int freeRes ; calculated each pass as a simple total-used valueint freeRooms ; The number of rooms free (max 5, min 0)int firstFreeRoom ; the number of the first free room.  Recall that rooms may be deleted, so you can't count on this being the last in the chain.  Is 0 if no rooms free (shouldn't be allowed to occur)int tempRfnd ; temporary variable, used to calculate cost refundsint tempRoom ; temporary variable, used to track which room type we're dealing withint whichRoom ; temporary variable, used to track which room slot we're dealing withint activateSomething; if set to 1, will check the other activations below (universal variable added to keep gameMode short)int activateTownsize ; if set to 1, will trigger the initial townSize menu (and set this to 0)int activateTimeout ; if set to 1, will trigger the construction sound and an imagespace modifier to delay the player; 2 does the same with a demolition sound, 3 the same with (undetermined) disable/damage sound; The following indicate that an action needs to be performed on a building.; 0 = no action needed; 1 = Build up one level; 2 = Demolish down one level; 3 = Damage building (level remains the same but becomes nonfunctional until repair cost paid); 4 = Disable building (as "damaged," but unfixable save by specific triggers); 6, 7, 8 = Upgrade to this sixth-tier building; 9 = Repair building; 10 = un-disable buildingint activateBuild01int activateBuild02int activateBuild03int activateBuild04int activateBuild05int activateBuild06int activateBuild07int activateBuild08int activateBuild09int activateBuild10int activateBuild11int activateBuild12; The following are used to pass information to messages - specifically, they're used to describe if the user has items/resources necessary.int passHasItems1int passHasRes1int passHasItems2int passHasRes2int passHasItems3int passHasRes3float timer ; used for timing functionsBegin OnActivate	if isMsg != 0 ; There's already a message up!		return	endif	if activateSomething > 0 ; GameMode must be handled before this can be safely selected!  Should only occur if the player activates very quickly after closing		return	endif	set freeRes to (a450ResTot - a450ResUsed)	if freeRes < 0		set freeRes to 0 ; Don't show negative resources.  It's just confusing.	endif	if a450EventsWaiting > 0 ; We have events to deal with!		set isMsg to 1		set whichMsg to 101		showMessage a450m101Events a450ResUsed a450ResTot freeRes a450Defense ; Events waiting message, standard stats	endif	; If no events are waiting, we'll need to calculate town size and show a proper window	; this is NOT handled here because menus need to be able to "return to main menu"	set activateTownsize to 1	set activateSomething to 1EndBegin GameMode	if activateSomething > 0		; activate means no menu is open (I think - watch this one)		; This is basically a shortcut so I don't have to do these two every time I set activateSomething		set isMsg to 0		set whichMsg to 0		; One of these variables will be true		if activateTimeout == 1			; Construction			if timer == 0 ; Uninitialized				;start				set timer to 1				DisablePlayerControls				playSound a450ConstructionSound				iMod FadeToBlack5sISFX				return			else				set timer to timer + getSecondsPassed				if timer > 6					;end					set activateSomething to 0					set activateTimeout to 0					set timer to 0					EnablePlayerControls				endif				return			endif		elseif activateTimeout == 2			; Demolish			if timer == 0 ; Uninitialized				;start				set timer to 1				DisablePlayerControls				playSound a450ConstructionSound				iMod FadeToBlack5sISFX				return			else				set timer to timer + getSecondsPassed				if timer > 6					;end					set activateSomething to 0					set activateTimeout to 0					set timer to 0					EnablePlayerControls				endif				return			endif				elseif activateTimeout == 3			; Disable/damaged			if timer == 0 ; Uninitialized				;start				set timer to 1				DisablePlayerControls				playSound a450ConstructionSound				iMod FadeToBlack5sISFX				return			else				set timer to timer + getSecondsPassed				if timer > 6					;end					set activateSomething to 0					set activateTimeout to 0					set timer to 0					EnablePlayerControls				endif				return			endif						endif		set activateSomething to 0		;Recalculate the first free room		if a450Slot1Type == 0			set firstFreeRoom to 1		elseif a450Slot2Type == 0			set firstFreeRoom to 2		elseif a450Slot3Type == 0			set firstFreeRoom to 3		elseif a450Slot4Type == 0			set firstFreeRoom to 4		elseif a450Slot5Type == 0			set firstFreeRoom to 5		else			set firstFreeRoom to 0		endif		if activateTownSize == 1			set activateTownSize to 0			set activateSomething to 0			set isMsg to 1						; Show main menu!			; Town size calculations: +1 per resource upgrade, +1 per un-empty room, +1 per building level up to 5, +1 for final tier upgrade			set townSize to a450SizeMod			; INSERT RESOURCE UPGRADE CALCULATIONS HERE			; We have to do this for every single possible room - all twelve, due to how they're stored.			if a450Room01State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room01State <= 5					set townSize to townSize + a450Room01State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room02State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room02State <= 5					set townSize to townSize + a450Room02State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room03State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room03State <= 5					set townSize to townSize + a450Room03State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room04State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room04State <= 5					set townSize to townSize + a450Room04State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room05State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room05State <= 5					set townSize to townSize + a450Room05State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room06State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room06state <= 5					set townSize to townSize + a450Room06State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room07State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room07State <= 5					set townSize to townSize + a450Room07State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room08State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room08State <= 5					set townSize to townSize + a450Room08State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room09State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room09State <= 5					set townSize to townSize + a450Room09State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room10State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room10State <= 5					set townSize to townSize + a450Room10State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room11State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room11State <= 5					set townSize to townSize + a450Room11State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif			if a450Room12State > 0				set townSize to townSize + 1 ; +1 Size for having a building				if a450Room12State <= 5					set townSize to townSize + a450Room12State ; +level for building levels up to 5				else					set townSize to townSize + 6 ; +5 for level 5 building and +1 for side-upgrade				endif			endif						; townSize calculations done.  Show message based on town Size.			if townSize <= 4				; Ruin				set whichMsg to 001				ShowMessage a450m001StatSize1 a450ResUsed a450ResTot freeRes a450Defense			elseif townSize <= 9				; Hamlet				set whichMsg to 002				ShowMessage a450m002StatSize2 a450ResUsed a450ResTot freeRes a450Defense			elseif townSize <=19				; Village				set whichMsg to 003				ShowMessage a450m003StatSize3 a450ResUsed a450ResTot freeRes a450Defense			elseif townSize <=29				; Town				set whichMsg to 004				ShowMessage a450m004StatSize4 a450ResUsed a450ResTot freeRes a450Defense			elseif townSize <=39				; City				set whichMsg to 005				ShowMessage a450m005StatSize5 a450ResUsed a450ResTot freeRes a450Defense			else				; Hub!				set whichMsg to 006				ShowMessage a450m006StatSize6 a450ResUsed a450ResTot freeRes a450Defense			endif			return		endif		; The following code handles all building upgrades/downgrades/etc.		; Resources must be subtracted from the player.  HOWEVER, it is assumed that the player has these resources (checks occur in menus)		if activateBuild01 != 0			set activateSomething to 0			if activateBuild01 != 3 && activateBuild01 != 4 && activateBuild01 != 9 && activateBuild01 != 10				; If we're not disabling, damaging, or repairing a building, we're going to first need to disable the objects currently in place.				; INSERT OBJECT DISABLING CODE HERE			endif			if activateBuild01 == 1				; 1 = Build up one level				; Process for upgrading: pay price (caps/items), pay resources, set proper variables, update room variables (INITIAL BUILD ONLY), enable and move visible objects, enable proper activateTimeout, activate building level effects				if a450Room01State == 0					; Initial Build					; Pay caps					set tempRfnd to 500					player.removeItem F tempRfnd					; Pay items					; Pay RESOURCES					set a450ResUsed to a450ResUsed + 2					; Variables					set a450Room01State to (a450Room01State + 1)					; SlotType					if firstFreeRoom == 1						set a450Slot1Type to 1						set a450Room01Place to 1					elseif firstFreeRoom == 2						set a450Slot2Type to 1						set a450Room01Place to 2					elseif firstFreeRoom == 3						set a450Slot3Type to 1						set a450Room01Place to 3					elseif firstFreeRoom == 4						set a450Slot4Type to 1						set a450Room01Place to 4					else						set a450Slot5Type to 1						set a450Room01Place to 5					endif					; EnableObjects					; INSERT ENABLE OBJECTS CODE HERE					; Trigger proper activateTimeout					set activateSomething to 1					set activateTimeout to 1					; Activate Building effects					set a450Defense to a450Defense + 2				elseif a450Room01State == 1					; Upgrade					; Pay caps					set tempRfnd to 1000					player.removeItem F tempRfnd					; Pay items					; Pay RESOURCES					set a450ResUsed to a450ResUsed + 1					; Variables					set a450Room01State to (a450Room01State + 1)					; EnableObjects					; INSERT ENABLE OBJECTS CODE HERE					; Trigger proper activateTimeout					set activateSomething to 1					set activateTimeout to 1					; Activate Building effects					set a450Room01Eff to a450Room01Eff + 1				elseif a450Room01State == 2					; Upgrade					; Pay caps					set tempRfnd to 2000					player.removeItem F tempRfnd					if a450BuildCostMult < 1						; Build cost refund						set tempRfnd to (tempRfnd * (1.0-a450BuildCostMult))						player.addItem F tempRfnd					endif					; Pay items					; Pay RESOURCES					set a450ResUsed to a450ResUsed + 1					; Variables					set a450Room01State to (a450Room01State + 1)					; EnableObjects					; INSERT ENABLE OBJECTS CODE HERE					; Trigger proper activateTimeout					set activateSomething to 1					set activateTimeout to 1					; Activate Building effects					set a450Defense to a450Defense + 2				elseif a450Room01State == 3					; Upgrade					; Pay caps					set tempRfnd to 3000					player.removeItem F tempRfnd					; Pay items					; Pay RESOURCES					set a450ResUsed to a450ResUsed + 2					; Variables					set a450Room01State to (a450Room01State + 1)					; EnableObjects					; INSERT ENABLE OBJECTS CODE HERE					; Trigger proper activateTimeout					set activateSomething to 1					set activateTimeout to 1					; Activate Building effects					set a450Room01Eff to a450Room01Eff + 2				elseif a450Room01State == 4					; Upgrade					; Pay caps					set tempRfnd to 4000					player.removeItem F tempRfnd					; Pay items					; Pay RESOURCES					set a450ResUsed to a450ResUsed + 1					; Variables					set a450Room01State to (a450Room01State + 1)					; EnableObjects					; INSERT ENABLE OBJECTS CODE HERE					; Trigger proper activateTimeout					set activateSomething to 1					set activateTimeout to 1					; Activate Building effects					set a450Defense to a450Defense + 2				endif ; 5+ handled below			elseif activateBuild01 == 2				; 2 = Demolish down one level			elseif activateBuild01 == 3				; 3 = Damage building (level remains the same but becomes nonfunctional until repair cost paid)			elseif activateBuild01 == 4				; 4 = Disable building (as "damaged," but unfixable save by specific triggers)			elseif activateBuild01 == 9				; Repair building			elseif activateBuild01 == 6					; Final upgrade - Spec Ops Training					; Pay caps					set tempRfnd to 5000					player.removeItem F tempRfnd					; Pay items					; Pay RESOURCES					set a450ResUsed to a450ResUsed + 3					; Variables					set a450Room01State to 6					; EnableObjects					; INSERT ENABLE OBJECTS CODE HERE					; Trigger proper activateTimeout					set activateSomething to 1					set activateTimeout to 1					; Activate Building effects					set a450Room01Eff to a450Room01Eff - 3 ; All level six upgrades lose their efficiency bonus from levels 2 and 4					; Do we have an Arsenal and is it in good condition?					if a450Room02State > 0 && a450Room02Cur == 0						; Arsenal present.  Determine current Barracks EFF+ and add it again.  Future checks/updates will be handled automatically by the Arsenal upgrade/downgrade code						if (a450Room02State == 1) || (a450Room02State == 2)							set a450Room01EFF to a450Room01EFF + 1						elseif (a450Room02State == 3) || (a450Room02State == 4)							set a450Room01EFF to a450Room01EFF + 2						elseif (a450Room02State == 5)							set a450Room01EFF to a450Room01EFF + 3						elseif (a450Room02State == 6)							; Militia Headquarters - no bonus!						elseif (a450Room02State == 7)							; War Room							set a450Room01EFF to a450Room01EFF + 4						elseif (a450Room02State == 8)							; Armory							set a450Room01EFF to a450Room01EFF + 3						endif					endif			elseif activateBuild01 == 7					; Final upgrade - Quarters					; Pay caps					set tempRfnd to 6000					player.removeItem F tempRfnd					; Pay items					; Pay RESOURCES					set a450ResUsed to a450ResUsed + 1					; Variables					set a450Room01State to 7					; EnableObjects					; INSERT ENABLE OBJECTS CODE HERE					; Trigger proper activateTimeout					set activateSomething to 1					set activateTimeout to 1					; Activate Building effects					set a450Room01Eff to a450Room01Eff - 3 ; All level six upgrades lose their efficiency bonus from levels 2 and 4					; Arsenal changes unnecessary; same as barracks			elseif activateBuild01 == 8					; Final upgrade -Dojo					; Pay caps					set tempRfnd to 5000					player.removeItem F tempRfnd					; Pay items					; Pay RESOURCES					set a450ResUsed to a450ResUsed + 2					; Variables					set a450Room01State to 8					; EnableObjects					; INSERT ENABLE OBJECTS CODE HERE					; Trigger proper activateTimeout					set activateSomething to 1					set activateTimeout to 1					; Activate Building effects					set a450Room01Eff to a450Room01Eff - 3 ; All level six upgrades lose their efficiency bonus from levels 2 and 4					; Do we have an Arsenal and is it in good condition?					if a450Room02State > 0 && a450Room02Cur == 0						; Arsenal present.  Determine current Barracks EFF+ and subtract it.  Future checks/updates will be handled automatically by the Arsenal upgrade/downgrade code						if (a450Room02State == 1) || (a450Room02State == 2)							set a450Room01EFF to a450Room01EFF - 1						elseif (a450Room02State == 3) || (a450Room02State == 4)							set a450Room01EFF to a450Room01EFF - 2						elseif (a450Room02State == 5)							set a450Room01EFF to a450Room01EFF - 3						elseif (a450Room02State == 6)							; Militia Headquarters - no bonus!						elseif (a450Room02State == 7)							; War Room							set a450Room01EFF to a450Room01EFF - 4						elseif (a450Room02State == 8)							; Armory							set a450Room01EFF to a450Room01EFF - 3						endif					endif			endif			set activateBuild01 to 0			; ----------------------------------------		endif		return ; Lets wait for the next frame, even if there's an isMsg to handle.	endif ; end of activateSomething check	if isMsg == 0		; No message up!  Just quit to decrease frame drag		return	endif		set btnPress to GetButtonPressed	if btnPress == -1		; A message is up, but we've received no input.  No reason to continue.		return	endif		;Recalculate free RESOURCES	set freeRes to (a450ResTot - a450ResUsed)	if freeRes < 0		set freeRes to 0 ; Don't show negative resources.  It's just confusing.	endif	;Recalculate # of free rooms in case we need it	set freeRooms to 5	if a450Slot1Type > 0		set freeRooms to freeRooms - 1	endif	if a450Slot2Type > 0		set freeRooms to freeRooms - 1	endif	if a450Slot3Type > 0		set freeRooms to freeRooms - 1	endif	if a450Slot4Type > 0		set freeRooms to freeRooms - 1	endif	if a450Slot5Type > 0		set freeRooms to freeRooms - 1	endif		;Recalculate the first free room	if a450Slot1Type == 0		set firstFreeRoom to 1	elseif a450Slot2Type == 0		set firstFreeRoom to 2	elseif a450Slot3Type == 0		set firstFreeRoom to 3	elseif a450Slot4Type == 0		set firstFreeRoom to 4	elseif a450Slot5Type == 0		set firstFreeRoom to 5	else		set firstFreeRoom to 0	endif		; If we get here, we know a button has been pressed in a menu.	if whichMsg >= 001 && whichMsg <= 005		; The main menu is up, displaying a size-specific message (which we don't care about).		; Possible options:		; 0 = Build New Room		; 1 = Inspect Current Rooms		; 2 = Build/Inspect Resource Structures		; 3 = Build/Inspect Defensive Structures		; 4 = Build/Inspect Miscellaneous Structures		; 5 = Goodbye		if btnPress == 0			set whichMsg to 300			showMessage a450m300BuildRoom freeRooms		elseif btnPress == 1			set whichMsg to 200			showMessage a450m200InspectRoom		elseif btnPress == 2			; INSERT RESOURCE MENU HERE			set whichMsg to 0			set isMsg to 0			return		elseif btnPress == 3			; INSERT DEFENSIVE MENU HERE			set whichMsg to 0			set isMsg to 0			return		elseif btnPress == 4			; INSERT MISC MENU HERE			set whichMsg to 0			set isMsg to 0			return		elseif btnPress == 5			set whichMsg to 0			set isMsg to 0			return		else			; Error state!		endif	elseif whichMsg == 300		; Build new room menu.  Options are:		; 0 = military		; 1 = industry		; 2 = Support		; 3 = Commerce		; 4 = Information		; 5 = return to main menu		; 6 = Goodbye		if btnPress == 0			set whichMsg to 381			showMessage a450m381BuildMilitary a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 1			set whichMsg to 382			showMessage a450m382BuildIndustry a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 2			set whichMsg to 383			showMessage a450m383BuildSupport a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 3			set whichMsg to 384			showMessage a450m384BuildCommerce a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 4			set whichMsg to 385			showMessage a450m385BuildInformation a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 5			; Return to proper town menu...			set activateTownSize to 1			set activateSomething to 1			return		elseif btnPress == 6			set whichMsg to 0			set isMsg to 0			return		endif	; 381-385 are category build menus	; All follow the response format:	; Alternating (2 or 3 choices) even being build and odd being (already built)	; final two options are return and goodbye	elseif whichMsg == 381		; 381 is build military menu, options are barracks/arsenal		if btnPress == 1 || btnPress == 3			; failed options, re-show message			showMessage a450m381BuildMilitary a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 0			; Barracks!			; Item check:			if Player.GetItemCount F >= 500				set passHasItems1 to 1			else				set passHasItems1 to 0			endif			; Resources check:			if freeRes >= 2				set passHasRes1 to 1			else				set passHasRes1 to 0			endif			set whichMsg to 301			showMessage a450m301BuildBarracks a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 2			set whichMsg to 302			showMessage a450m302BuildArsenal a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 4			set whichMsg to 300			showMessage a450m300BuildRoom freeRooms		elseif btnPress == 5			set whichMsg to 0			set isMsg to 0			return					endif	elseif whichMsg == 382		; 382 is build industry menu, options are 3worskhop/9lab		if btnPress == 1 || btnPress == 3			; failed options, re-show message			showMessage a450m382BuildIndustry a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 0			set whichMsg to 303			showMessage a450m303BuildWorkshop a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 2			set whichMsg to 309			showMessage a450m309BuildLaboratory a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 4			set whichMsg to 300			showMessage a450m300BuildRoom freeRooms		elseif btnPress == 5			set whichMsg to 0			set isMsg to 0			return					endif	elseif whichMsg == 383		; 383 is build support menu, options are 4lounge/6infirmary/12galley		if btnPress == 1 || btnPress == 3 || btnPress == 5			; failed options, re-show message			showMessage a450m383BuildSupport a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 0			set whichMsg to 304			showMessage a450m304BuildLounge a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 2			set whichMsg to 306			showMessage a450m306BuildInfirmary a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 4			set whichMsg to 312			showMessage a450m312BuildGalley a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 6			set whichMsg to 300			showMessage a450m300BuildRoom freeRooms		elseif btnPress == 7			set whichMsg to 0			set isMsg to 0			return					endif	elseif whichMsg == 384		; 384 is commerce support menu, options are 7shop/8bar/10bank		if btnPress == 1 || btnPress == 3 || btnPress == 5			; failed options, re-show message			showMessage a450m384BuildCommerce a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 0			set whichMsg to 307			showMessage a450m307BuildShop a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 2			set whichMsg to 308			showMessage a450m308BuildBar a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 4			set whichMsg to 310			showMessage a450m310BuildBank a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 6			set whichMsg to 300			showMessage a450m300BuildRoom freeRooms		elseif btnPress == 7			set whichMsg to 0			set isMsg to 0			return					endif	elseif whichMsg == 385		; 385 is build information menu, options are 5library/11guild		if btnPress == 1 || btnPress == 3			; failed options, re-show message			showMessage a450m385BuildInformation a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 0			set whichMsg to 305			showMessage a450m305BuildLibrary a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 2			set whichMsg to 311			showMessage a450m311BuildGuild a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 4			set whichMsg to 300			showMessage a450m300BuildRoom freeRooms		elseif btnPress == 5			set whichMsg to 0			set isMsg to 0			return					endif	; Beginning the final building-specific build menus.	; These are all very simple, 3-option affairs.	; 0 = Being Construction	; 1, 2 = Fail	; 3 = Return	; 4 = Exit	elseif whichMsg == 301		; Barracks		if btnPress == 0			set activateBuild01 to 1			set activateSomething to 1		elseif btnPress == 1 || btnPress == 2					set whichMsg to 301			showMessage a450m301BuildBarracks a450ResUsed a450ResTot freeRes a450Defense firstFreeRoom		elseif btnPress == 3			set whichMsg to 381			showMessage a450m381BuildMilitary a450ResUsed a450ResTot freeRes a450Defense		elseif btnPress == 4			set whichMsg to 0			set isMsg to 0			return					endif	elseif whichMsg == 200		; Inspect room menu.  Options are 0 = room1 -> 4 = room 5, 5 = return, 6 = goodbye		if btnPress < 5			if btnPress == 0				set whichRoom to 1				set tempRoom to a450Slot1Type			elseif btnPress == 1				set whichRoom to 2				set tempRoom to a450Slot2Type			elseif btnPress == 2				set whichRoom to 3				set tempRoom to a450Slot3Type			elseif btnPress == 3				set whichRoom to 4				set tempRoom to a450Slot4Type			elseif btnPress == 4				set whichRoom to 5				set tempRoom to a450Slot5Type			endif			if tempRoom == 1				; Inspect Room menu, Barracks				if a450Room01Cur == -1					; Room damaged					; Can we afford repairs?					if (a450Room01State == 1 && Player.GetItemCount F >= 250) || (a450Room01State == 2 && Player.GetItemCount F >= 500) || (a450Room01State == 3 && Player.GetItemCount F >= 1000) || (a450Room01State == 4 && Player.GetItemCount F >= 1500) || (a450Room01State == 5 && Player.GetItemCount F >= 2000) || (a450Room01State > 5 && Player.GetItemCount F >= 3000)						set passHasItems1 to 1					else						set passHasItems1 to 0					endif					set whichMsg to 261					showMessage a450m261InspectDamBarracks freeRes a450Room01Place a450Room01EFF a450Room01State				elseif a450Room01Cur > 0					; Room disabled					set whichMsg to 241					showMessage a450m241InspectDisBarracks freeRes a450Room01Place a450Room01EFF a450Room01State				elseif a450Room01State <= 4					; Between rank 1 and 4, inclusive					; ADD ITEM CHECKS TO THESE STATEMENTS LATER					; Based on current level, check to make sure we can afford upgrade to next rank, and prepare this information for the upcoming menu					if a450Room01State == 1						if Player.GetItemCount F > 1000							set passHasItems1 to 1						else							set passHasItems1 to 0						endif						if freeRes >= 1							set passHasRes1 to 1						else							set passHasRes1 to 0						endif					elseif a450Room01State == 2						if Player.GetItemCount F > 2000							set passHasItems1 to 1						else							set passHasItems1 to 0						endif						if freeRes >= 1							set passHasRes1 to 1						else							set passHasRes1 to 0						endif					elseif a450Room01State == 3						if Player.GetItemCount F > 3000							set passHasItems1 to 1						else							set passHasItems1 to 0						endif						if freeRes >= 2							set passHasRes1 to 1						else							set passHasRes1 to 0						endif					else						; Assume == 4						if Player.GetItemCount F > 4000							set passHasItems1 to 1						else							set passHasItems1 to 0						endif						if freeRes >= 1							set passHasRes1 to 1						else							set passHasRes1 to 0						endif					endif					set whichMsg to 201					showMessage a450m201InspectBarracks freeRes a450Room01Place a450Room01EFF a450Room01State				elseif a450Room01State == 5					set whichMsg to 221					showMessage a450m221InspectL5Barracks freeRes a450Room01Place a450Room01EFF														elseif a450Room01State == 6					set whichMsg to 401					showMessage a450m401InspectBarracks6 freeRes a450Room01Place a450Room01EFF					elseif a450Room01State == 7					set whichMsg to 402					showMessage a450m402InspectBarracks7 freeRes a450Room01Place a450Room01EFF					elseif a450Room01State == 8					set whichMsg to 403					showMessage a450m403InspectBarracks8 freeRes a450Room01Place a450Room01EFF					endif			endif		elseif btnPress == 5			; Return to proper town menu...			set activateTownSize to 1			set activateSomething to 1			return		elseif btnPress == 6			; Goodbye			set whichMsg to 0			set isMsg to 0			return		endif	; All regular room inspections follow the same 5-option pattern	; 0 = upgrade	; 1, 2 = failed option (redisplay menu)	; 3 = downgrade	; 4 = demolish (same as downgrade, just only visible at rank 1)	; 5 = return	; 6 = goodbye	elseif whichMsg == 201 ; Inspect Barracks, level 1-4		if btnPress == 0			set activateSomething to 1			set activateBuild01 to 1		elseif btnPress == 1 || btnPress == 2			; Failed options			showMessage a450m201InspectBarracks freeRes a450Room01Place a450Room01EFF a450Room01State		elseif btnPress == 3 || btnPress == 4			; Downgrade/Demolish			set activateSomething to 1			set activateBuild01 to 2		elseif btnPress == 5			; Return			set whichMsg to 200			showMessage a450m200InspectRoom		elseif btnPress == 6			; Goodbye			set whichMsg to 0			set isMsg to 0			return		endif	elseif whichMsg == 221 ; Inspect Barracks, level 5		; 0, 1, 2 = info pane for upgrades value 6, 7, 8		; 3 = Downgrade to level 4		; 4 = return		; 5 = Goodbye		if btnPress == 0			; Building option 6			; Spec Ops			if Player.GetItemCount F > 5000				set passHasItems1 to 1			else				set passHasItems1 to 0			endif			if freeRes >= 3				set passHasRes1 to 1			else				set passHasRes1 to 0			endif			set whichMsg to 401			showMessage a450m401InspectBarracks6 freeRes a450Room01Place a450Room01EFF		elseif btnPress == 1			; Building option 7			; Quarters			if Player.GetItemCount F > 6000				set passHasItems1 to 1			else				set passHasItems1 to 0			endif			if freeRes >= 1				set passHasRes1 to 1			else				set passHasRes1 to 0			endif			set whichMsg to 402			showMessage a450m402InspectBarracks7 freeRes a450Room01Place a450Room01EFF		elseif btnPress == 2			; Building option 8			; Dojo			if Player.GetItemCount F > 5000				set passHasItems1 to 1			else				set passHasItems1 to 0			endif			if freeRes >= 2				set passHasRes1 to 1			else				set passHasRes1 to 0			endif			set whichMsg to 403			showMessage a450m403InspectBarracks8 freeRes a450Room01Place a450Room01EFF		elseif btnPress == 3			set activateSomething to 1			set activateBuild01 to 2		elseif btnPress == 4			; Return			set whichMsg to 200			showMessage a450m200InspectRoom		elseif btnPress == 5			; Goodbye			set whichMsg to 0			set isMsg to 0		endif	; 401 -> 436(?) are combination menus that pop up if EITHER a player is considering upgrading to a tier six building OR he/she has already done so and is re-specting the building	; 0 = Build this lvl 6 upgrade	; 1, 2 = fail options, return to same menu	; 3 = Downgrade to level 4 (lvl 6 upgrade unbuilt)	; 4 = Downgrade to level 5 (lvl 6 upgrade built)	; 5 = Return, lvl 5 version (return to inspectl5 version)	; 6 = Return, lvl 6 version (return to main inspect menu)	; 7 = Goodbye	elseif whichMsg == 401		if btnPress == 0			; Build lvl 6 upgrade			set activateSomething to 1			set activateBuild01 to 6		elseif btnPress == 1 || btnPress == 2			; Reset menu			set whichMsg to 401			showMessage a450m401InspectBarracks6 freeRes a450Room01Place a450Room01EFF		elseif btnPress == 3 || btnPress == 4			; Demolish			set activateSomething to 1			set activateBuild01 to 2		elseif btnPress == 5			; Return lvl 5			set whichMsg to 221			showMessage a450m221InspectL5Barracks freeRes a450Room01Place a450Room01EFF			elseif btnPress == 6			; Return lvl 6			set whichMsg to 200			showMessage a450m200InspectRoom		elseif btnPress == 7			; Goodbye			set whichMsg to 0			set isMsg to 0		endif	elseif whichMsg == 402		if btnPress == 0			; Build lvl 6 upgrade			set activateSomething to 1			set activateBuild01 to 7		elseif btnPress == 1 || btnPress == 2			; Reset menu			set whichMsg to 402			showMessage a450m402InspectBarracks7 freeRes a450Room01Place a450Room01EFF		elseif btnPress == 3 || btnPress == 4			; Demolish			set activateSomething to 1			set activateBuild01 to 2		elseif btnPress == 5			; Return lvl 5			set whichMsg to 221			showMessage a450m221InspectL5Barracks freeRes a450Room01Place a450Room01EFF			elseif btnPress == 6			; Return lvl 6			set whichMsg to 200			showMessage a450m200InspectRoom		elseif btnPress == 7			; Goodbye			set whichMsg to 0			set isMsg to 0		endif	elseif whichMsg == 403		if btnPress == 0			; Build lvl 6 upgrade			set activateSomething to 1			set activateBuild01 to 8		elseif btnPress == 1 || btnPress == 2			; Reset menu			set whichMsg to 403			showMessage a450m403InspectBarracks8 freeRes a450Room01Place a450Room01EFF		elseif btnPress == 3 || btnPress == 4			; Demolish			set activateSomething to 1			set activateBuild01 to 2		elseif btnPress == 5			; Return lvl 5			set whichMsg to 221			showMessage a450m221InspectL5Barracks freeRes a450Room01Place a450Room01EFF			elseif btnPress == 6			; Return lvl 6			set whichMsg to 200			showMessage a450m200InspectRoom		elseif btnPress == 7			; Goodbye			set whichMsg to 0			set isMsg to 0		endif	else		; Error state - unhandled menu!  Just treat it like a "goodbye"		set whichMsg to 0		set isMsg to 0	endifEndBegin onLoad	; DEBUG CODE	set a450Room01Eff to 5	set a450Room01Place to 1	set a450Room01State to 5	set a450ResTot to 20	set a450Slot1Type to 1End

User avatar
Gracie Dugdale
 
Posts: 3397
Joined: Wed Jun 14, 2006 11:02 pm


Return to Fallout: New Vegas