More Broken Code

Metraxis

Member
Alright, I'm ironing out the last/latest kinks in a quest-related script (which quest should be obvious), but one part of the code is not working as I expect. Here's the snippet:
Code:
		<snip 384 lines>
		goal TowerItem;
		TowerItem.type = "IA";

		item TowerNeed;
		<snip map definitions>
		if(contains_text(OpenLog,"The Final Ultimate Epic Final Conflict")) {
			if(!contains_text(OpenLog, "You have defeated the Naughty Sorceress and freed the King!")) {
				<snip entryway>
				<snip hedge maze>
				<snip Nagamar paranioa>
				TowerNeed = guardians();
--Begin problem segment
>				if(TowerNeed == $item[NG]) {
>					if(item_amount($item[lowercase n]) == 0) {
>						TowerNeed = $item[lowercase n];
>					} else {
>						TowerNeed = $item[original G];
>					}
>				}
--End Problem segment
				if(TowerNeed == $item[barbed-wire fence]) { 
					TowerNeed = $item[white picket fence]; 
					print("Substituting white picket fence. Obtain DoD wand");
					wait(5);
				}
				if(TowerNeed != $item[none]) {
					TowerItem.ItemList[TowerNeed] = 1;
					TowerItem.area = TowerMap[TowerNeed];
					if(TowerItem.area == $location[Guano Junction]) {
						if(stench_resistance() < .001) {
							TowerItem.BuffList[$effect[Elemental Saucesphere]] = 1;
						}
					}
					return TowerItem;
				}
				print("Complete Chamber and Defeat Sorceress");
				result.type = "X";
				return result;
			}
		}
		<snip 600 lines>

Here's the problem:
When fighting a Desktop Globe, the guardians() function returns an item which item_to_string() identifies as NG. However, the if() statement evaluates to false (I verified this by running the script with a print("NG"); after the if(), showing that execution never got into that section.) and so does not change TowerNeed to $item[lowercase n], as it should (since I have none in inventory, but have 5 original Gs).

I suspect either I have screwed something up subtly, or there is a problem somewhere else (just like everyone else whose code fails) ;D Any thoughts?
 

Nightmist

Member
If you don't mind could you upload the file, because working with a partial image of a script can end up being more confusing since you can only guess where stuff is happening.

You do have a adventure command at the "TowerItem.area" right? Because theres none in that posted section? (Although it does do a return TowerItem so I also suspect thats where the adventuring happens but just making sure)
 

Metraxis

Member
The problem is strictly with the if() misbehaving, and while I'd rather not post the whole file (it has many of the characteristics of an ascension script), I'd be happy to email/PM it to you.

You are correct. TowerMap is a location [item] map which identifies the locations in which the various tower-monster-killing items are found. The area member of the goal record type identifies the location in which the adventuring will be done.
 

Nightmist

Member
Uh assuming you haven't manually bypassed the globe yet then could you run this?
Code:
item TowerNeed = guardians();
print( item_to_string( TowerNeed));
if( TowerNeed == $item[NG]){ print( "Debug 1A");}else{ print( "Debug 1B");}
if( TowerNeed != $item[NG]){ print( "Debug 2A");}else{ print( "Debug 2B");}
if( item_to_string( TowerNeed) == item_to_string( $item[NG]){ print( "Debug 3A");}else{print( "Debug 3B");}
if( item_to_string( TowerNeed) != item_to_string( $item[NG]){ print( "Debug 4A");}else{print( "Debug 4B");}
if( item_to_int( TowerNeed) == item_to_int( $item[NG]){ print( "Debug 5A");}else{print( "Debug 5B");}
if( item_to_int( TowerNeed) != item_to_int( $item[NG]){ print( "Debug 6A");}else{print( "Debug 6B");}
Yeah the switching between == and != is pretty redundant but you never know, might find something.
Oh and in your script, make it print what it's left with after all the checks for what item you need. (Find what it's returning for the "return TowerItem;")
 

holatuwol

Developer
What does item_to_string( $item[NG] ) show you? There was a glitch in the first release of 9.8 which could potentially return "chewing gum on a string" for that, but that should have been resolved in the second release of 9.8.
 

Nightmist

Member
[quote author=holatuwol link=topic=590.msg2834#msg2834 date=1164182027]
What does item_to_string( $item[NG] ) show you? There was a glitch in the first release of 9.8 which could potentially return "chewing gum on a string" for that, but that should have been resolved in the second release of 9.8.
[/quote]

Well mainly because of this:
[quote author=Metraxis link=topic=590.msg2829#msg2829 date=1164094688]
When fighting a Desktop Globe, the guardians() function returns an item which item_to_string() identifies as NG. However, the if() statement evaluates to false[/quote]
Since a print with item_to_string() works "properly" just making sure that if a direct item to item check fails then checking if a string to string of that works. (The item_to_string at the start is just to make sure we DO infact have a NG as the tower item)
 

holatuwol

Developer
Right ... I was wondering if $item[NG] was also printing as NG, because it's entirely possible it wasn't.
 

Metraxis

Member
After adding this snippet:
Code:
				TowerNeed = guardians();
			if(TowerNeed != $item[none]) {
				print(item_to_string(TowerNeed));
				print(item_to_string($item[NG]));
				wait(5);
			}
I get this output:
Code:
 Checking prerequisites...
Climbing the tower...
Fighting guardian on level 4 of the tower...
Encounter: Giant Desktop Globe
Verifying ingredients for NG...
You need 1 more lowercase N to continue.
NG
orange
Countdown: 5 seconds...
Countdown: 4 seconds...
Countdown: 3 seconds...
Countdown: 2 seconds...
KoLmafia declares world peace.
Waiting completed.
Script aborted!

When I created this topic, I was using Daily build 2390. The above text is from Daily build 2402, which I assume is at least as recent as the current release version, so you're right on the money when asking about $item[NG], which appears to be displaying as 'orange'.

For now, the problem is moot, but as it appears to bear on a bug in KolMafia itself, I'm perfectly happy to delay ascending again to help fix it if needed. (ie I acquired the lowercase n manually, but hid it from the item creator by combining it with a heavy d I had laying around, and so can fight the globe up to 80 more times today)
 

holatuwol

Developer
Okay, it turns out it's due to case sensitivity. I believe $item[ng] will give you NG when converted to a string instead of an orange. I've gone ahead and fixed the case-sensitivity issue for the next release, but for your script, I'd recommend using the all-lowercase version.
 

Metraxis

Member
Yep. Switching from $item[NG] to $item[ng] works. I wonder, though, if case-sensitivity is a positive feature, particularly in location names, where $location[Haunted Gallery] != $location[haunted Gallery].
 
Top