I wrote this function to get any requested foldable item, specifically so I can be sure to have a diaper and moondial available for my rollover script. Any thoughts if I could have done it a better way? (didn't PHP tag this, apostrophes in items names gave it fits)
EDIT: Rediculously improved by lostcal's suggestion
EDIT: Rediculously improved by lostcal's suggestion
Code:
boolean get_foldable(item wanted){
// Maybe we already have the item we want? Get it and stop searching!
if( available_amount(wanted) > 0){
retrieve_item(1, wanted);
vprint("Happy day! You already have a " + wanted,"blue",2);
return true;
}
// Maybe we have another item we can squeeze into what we want?
foreach it in get_related(wanted, "fold"){
if( available_amount(it) > 0 ){
// Found it! Retrieve the item, squeeze what we wanted and stop looking for others
retrieve_item(1, it);
cli_execute("squeeze " + wanted);
vprint("Successfully squeezed a " + wanted,"blue",2);
return true;
}
}
vprint("Sorry, couldn't find anything to squeeze into a " + wanted,"red",2);
return false;
}
Last edited: