BatBrain -- a central nervous system for consult scripts

Winterbay

Active member
I've found an interesting error in zlib -> batbrain -> wham -> autobasement (i.e. the last crashed while fighting a monster with WHAM which calls batbrain which calls zlib):
Code:
[COLOR=red]Expression evaluation error: Can't take square root of a      negative value (zlib.ash, line 162)[/COLOR]

This is from evaluating "love song of vague ambiguity" as an attack option. I added some print outs to WHAM to see where it happened and the following snippet is what I narrowed it down to:
Code:
            print("Enqueueueing");
            enqueue(killer);
            print("Monster HP is now (after queueueue) " + monster_stat("hp"));
            print("Enquueueueued");

A run of the script shows:
Code:
Enqueueueing
[COLOR=black]Queued: skill 2022[/COLOR]
[COLOR=black]Building      options...[/COLOR]
[COLOR=red]Expression evaluation error: Can't      take square root of a negative value (zlib.ash, line 162)[/COLOR]

So it happens somewhere in the enqueue-function before WHAM gets back control after enqueueing the skill.

Looking closer we see that enqueue() calls set_happened() which prints out the "Queued: skill 2022"-message followed by build_options(). Build_options calls build_items() which is where the crash occurs. Now, the problem is that after enqueueing skill 2022 the monster HP is -75.69 and as such the monster is dead so we won't need to update the options. Batbrain doesn't care about this and moves on anyway which with the new addition of not being able to take the root out of negative numbers makes the script crash.

I suggest adding a check for monster_stat("hp") being less than 0 in build_options() and either setting it to 0 before moving on, or just exit said function in that case.
 

zarqon

Well-known member
That's just a formula error in batfactors -- the formulas now need to replace sqrt(expression) with sqrt(max(0,expression)). Negative monster HP is possibly handy for scripts when fighting things like unknown monsters, or the Seal Clubber nemesis demon (where mafia treats damage to the shells as damage to the monster).
 

Theraze

Active member
BatBrain/WHAM decided to use items during my Azazel quest collection. Normally fine, except the items that it decided to use are the imp airs and bus passes that I was trying to use to finish the quest... not so good. Quote:
Round 2: Theraze uses the seal tooth and uses the bus pass!
Oh joy! Trying to avoid this issue by modifying the placeholder-removal section like so:
Code:
foreach ty,in,rec in factors {                 // remove placeholders, reduce ranges to averages, tune damage
   string deranged(string sane) {
      matcher rng = create_matcher("\\{.+?,(.+?),.+?}",sane);
      while (rng.find()) sane = sane.replace_string(rng.group(0),rng.group(1));
      return sane;
   }
   if (contains_text(rec.special,"custom")) { remove factors[ty,in]; continue; }
   if (ty == "item" && (to_item(in) == $item[bus pass] || to_item(in) == $item[imp air]) && get_property("questM10Azazel") != "finished") { remove factors[ty,in]; continue; }
   factors[ty,in].dmg = deranged(rec.dmg);
   factors[ty,in].pdmg = deranged(rec.pdmg);
   factors[ty,in].special = deranged(rec.special);
   foreach kw in $strings[prismatic,pasta,sauce,perfect] if (factors[ty,in].dmg.contains_text(kw))
      factors[ty,in].dmg = factors[ty,in].dmg.replace_string(kw,normalize_dmgtype(kw));
   if (ty == "skill") {
      if (to_skill(in) == $skill[weapon of the pastalord] && !contains_text(factors[ty,in].dmg,"none"))
         factors[ty,in].dmg += ",none";
   }
}
Basically, added
Code:
   if (ty == "item" && (to_item(in) == $item[bus pass] || to_item(in) == $item[imp air]) && get_property("questM10Azazel") != "finished") { remove factors[ty,in]; continue; }
after the custom-removal section. Hope it'll work, but there might be more tweaking left. Unfortunately, I didn't get the problem figured out until after my second failed finish... down to 13 adventures left on this character for today. Ah well. Hopefully it'll just... work.

Edit: Appears to. WHAM is now using the seal tooth by itself instead of throwing out another of my bus passes. Though that could be because I didn't have any bus passes left... however, it hasn't (re)used any of my imp airs, and I ended my 13 turns with 3 in inventory. Hopefully tomorrow I'll get to actually finish the quest.
 
Last edited:

Winterbay

Active member
You could also do a similar change to ok() in WHAM to get the same effect I guess (which is what I've now done locally).
 

Theraze

Active member
I could... but I can't think of a single time when I'd want to manually use it in BatMan or any other script that uses BatBrain. As such, my change was to BatBrain itself... :)
 

Magus_Prime

Well-known member
It seems that r11386 breaks Batbrain.

Code:
[582] Ninja Snowmen
Encounter: Ninja Snowman Janitor
Round 0: Arbos wins initiative!
Reserved word 'in' cannot be a key variable name (BatBrain.ash, line 475)
Consult script 'WHAM.ash' not found.
You're on your own, partner.
 

Bale

Minion
You can replayce lines 475-491 with these:

Code:
foreach ty,inx,rec in factors {                 // remove placeholders, reduce ranges to averages, tune damage
   string deranged(string sane) {
      matcher rng = create_matcher("\\{.+?,(.+?),.+?}",sane);
      while (rng.find()) sane = sane.replace_string(rng.group(0),rng.group(1));
      return sane;
   }
   if (contains_text(rec.special,"custom")) { remove factors[ty,inx]; continue; }
   factors[ty,inx].dmg = deranged(rec.dmg);
   factors[ty,inx].pdmg = deranged(rec.pdmg);
   factors[ty,inx].special = deranged(rec.special);
   foreach kw in $strings[prismatic,pasta,sauce,perfect] if (factors[ty,inx].dmg.contains_text(kw))
      factors[ty,inx].dmg = factors[ty,inx].dmg.replace_string(kw,normalize_dmgtype(kw));
   if (ty == "skill") {
      if (to_skill(inx) == $skill[weapon of the pastalord] && !contains_text(factors[ty,inx].dmg,"none"))
         factors[ty,inx].dmg += ",none";
   }
}
 

zarqon

Well-known member
De-ranged!! HAHAHAHAHAHA WHAT A BRILLIANT PUN ZARQON YOUR VARIABLE AND FUNCTION NAMES ARE GENIUS

Except sometimes. Stupid variable name fixed in 1.25. Also, BatBrain will now avoid throwing any items which are goals.
 

Bale

Minion
De-ranged!! HAHAHAHAHAHA WHAT A BRILLIANT PUN ZARQON YOUR VARIABLE AND FUNCTION NAMES ARE GENIUS

They are. They are. When reading your scripts I often stop and look at an odd name, wonder why you call it that and burst out in spontaneous laughter at the unexpected humor. (In that order.) If anyone asked my why you write scripts I'd have to tell them that you're in it for the lols.
 

zarqon

Well-known member
Would that it were true. Unfortunately, day-to-day survival is also a motive for many of the world's inhabitants. In my case, however, Bale's made a fair cop; I'd say I am in it for the satisfaction of making language elicit as much as it can. Including lols.
 

charred

Member
ive been getting the upgrade message for batbrain for a long time now even though i have made sure ive upgraded many times.
i have 1.25 but i keep getting the message in my gcli to upgrade
Code:
New Version of BatBrain Available: 1.25
Upgrade from 1.21 to 1.25 here!
even though my final line in the script reads:
Code:
string BBver = check_version("BatBrain","batbrain","1.25",6445);
everything seems to be working, its just annoying me that it keeps notifying me to upgrade even though i dont need to. any ideas?
 

charred

Member
checked my folders and cant find another copy.
decided to try to remove scripts to check. moved batbrain out of mafia and got errors from smartstasis
moved smartstasis out and was getting errors from fight.ash (batbrain relay)
removed fight.ash and im not getting any more errors, but surprisingly im still getting the upgrade batbrain message in the gcli
you might be on the right track. ive looked through all my script and relay folders and subfolders though

edit:
went through removing scripts, and the only time it stopped advising me to update batbrain was when i had every script in my folder except zlib

edit2: found adventure.ash in my relay folder looking for 1.21 batbrain. now i gotta figure out what that was even for

edit3: adventure.ash was part of batrelay and i must have had an older version because:
Code:
5.08.12 - ver. 1.2 changes: ..... Begin version checking transition to "BatMan RE". Remove version checking from adventure.ash and only decorate the page if it contains "adventure.php".
 
Last edited:

Bale

Minion
Awesome change today that BatBrain needs to learn about.

Instead of missing, normal attacks now do half base damage without any bonuses. (eg a power 100 weapon will do 5-10 damage instead of missing.)

I'm afraid I still don't know the fate of LTS and the like. Can anyone else here discover if they can still miss?
 
Last edited:
Top