if(!in_hardcore()) question

Pazleysox

Member
Here's what I'm trying to do.

Code:
void main()

do stuff here

if(!in_hardcore()) gohere();

do stuff here

void gohere()

Function 'gohere( )' undefined. This script may require a more recent version of KoLmafia and/or its supporting scripts.

is what I get. I know there's a simple way around this, but I'm not seeing it...
 

Veracity

Developer
Staff member
Either put gohere() farther up in the file before you call it, or put a "forward reference" to it before you call it. That would be:

void gohere();
 

Pazleysox

Member
Either put gohere() farther up in the file before you call it, or put a "forward reference" to it before you call it. That would be:

void gohere();


Is there another way to do this? I tried this, and got the same error.

Essentially what I'm trying to do is skip a chunk of code that I don't want to check if user is in hardcore. It's a rollover script that I'm updating for someone.
 

Veracity

Developer
Staff member
You want a goto statement? Uh, no.

Put the stuff you want to "skip over" in its own function - or in the block associated with an if statement that is controlled by the "conditional" associated with the if.
 

Pazleysox

Member
You want a goto statement? Uh, no.

Put the stuff you want to "skip over" in its own function - or in the block associated with an if statement that is controlled by the "conditional" associated with the if.

Code:
if ($item[time sword].available_amount() > 0 && (have_familiar($familiar[Disembodied Hand]) && (!in_hardcore())))
			{
   				use_familiar($familiar[Disembodied Hand]);
					equip($slot[familiar], $item[time sword]);		
			}

This would check for time sword first, disembodied hand second, and hardcore third, right?

If this i the case, can I do it this way:

Code:
if (!in_hardcore() && ($item[time sword].available_amount() > 0 && (have_familiar($familiar[Disembodied Hand])))))
			{
   				use_familiar($familiar[Disembodied Hand]);
					equip($slot[familiar], $item[time sword]);		
			}

Or is that two ways of saying exactly the same thing?
 

lostcalpolydude

Developer
Staff member
Those are the same thing, basically. You really don't need all those parentheses though, when you're just using && to compare all of your boolean expressions.

Code:
if (!in_hardcore() && $item[time sword].available_amount() > 0 && have_familiar($familiar[Disembodied Hand])))
is a perfectly good line. If you start mixing && and || then using parentheses becomes important to make sure you know what order things will be compared in.
 

Pazleysox

Member
Part of the same script, so I'll keep it in the same thread.

Code:
	print ("Maxamizing turn count... This might take a moment, we have a lot to check...", "Blue");
	if ($item[time sword].available_amount() > 0 && (have_familiar($familiar[Disembodied Hand])&&(!in_hardcore())))
			{
   				use_familiar($familiar[Disembodied Hand]);
					equip($slot[familiar], $item[time sword]);		
			}
	else if($item[solid shifting time weirdness].available_amount() > 0 &&(!in_hardcore()))
			{
					equip($slot[familiar], $item[solid shifting time weirdness]);
			}
	else if ($item[The Nuge's favorite crossbow].available_amount() > 0 && (have_familiar($familiar[Disembodied Hand])&&(!in_hardcore())))
			{
   				use_familiar($familiar[Disembodied Hand]);
					equip($slot[familiar], $item[The Nuge's favorite crossbow]);
			}
	else if($item[li'l unicorn costume].available_amount() == 0 && (have_familiar($familiar[Trick-or-Treating Tot])))
		{
		cli_execute ("buy li'l unicorn costume");
		}
	else if ($item[li'l unicorn costume].available_amount() > 0 && (have_familiar($familiar[Trick-or-Treating Tot])))
			{
   				use_familiar($familiar[Trick-or-Treating Tot]);
					equip($slot[familiar], $item[li'l unicorn costume]);
			}

        cli_execute("maximize adv -tie -familiar");

	print("Finished checking for rollover adventures.", "green");

The script doesn't look past the time shifting weirdness, regardless of other items being available.
 

Bale

Minion
As soon as an if() is true, it won't bother with the else.

In other words...

if($item[solid shifting time weirdness].available_amount() > 0 &&(!in_hardcore()))
else... who cares?

Solution? Remove the word else and just have a succession of unconnected if statements.
 

Crowther

Active member
I think you might want to use "can_interact()" instead of "!in_hardcore()". The player might be hardcore for life, but it seems more accurate.
 

Darzil

Developer
Personally I just shortcircuit all that with :

maximize("adv, 0.1 pvp fights +switch trick-or-treating tot", false);
Can add +switch disembodied hand in if you want to consider time sword too, and can always weight adventures and fights differently.
 

ckb

Minion
Staff member
That looks... way more complicated than it needs to be.
First, you are using 'else if', so it will stop after the first check that evaluates true. So if you have a time shifting weirdness, and not a hand+time sword, it will stop there.
Second, Mafia can maximize with familiars too, if you tell it to.
Try this:

PHP:
	print ("Maxamizing turn count... This might take a moment, we have a lot to check...", "Blue");
	if($item[li'l unicorn costume].available_amount()==0 && have_familiar($familiar[Trick-or-Treating Tot])) {
		buy(1,$item[li'l unicorn costume]);
	}
	maximize("adv, +switch Disembodied Hand, +switch Trick-or-Treating Tot", false);
	print("Finished checking for rollover adventures.", "green");

edit: triple ninja'ed!
 
Top