PDA

View Full Version : Global Variables



Danical
07-01-2008, 12:27 AM
I've 2 instances of Lich running. I just came back from a hunt in which I killed something.

This is one of them.

J>;e echo $slavedeath
--- Lich: exec1 active.
[exec1: true]
--- Lich: exec1 has finished.

J>;e echo $slaveskintarget
--- Lich: exec1 active.
[exec1: magus]
--- Lich: exec1 has finished.

This is the other.

>;e echo $slavedeath
--- Lich: exec1 active.
[exec1: false]
--- Lich: exec1 has finished.

What in the hellballs?

Code for first.



$slavedeath = false

while true
line = waitfor("directing the sound of his voice", "YOU HAVE BEEN IDLE TOO LONG", "player whispers(.+) mana")
if line =~ /directing the sound of his voice (.+) (triton|siren|Grimswarm)/
fput "incant 906"
line = waitfor("(rolls over|falls to the ground) and dies", "topples to the ground motionless", "a wrathful look on", "shudders violently", "shudders one last time", "going still", "death overtakes", "Your armor prevents the song from working correctly", "twitching for a moment before", "begins to dissolve from the bottom up", "gives a plaintive wail before she slumps to her side and dies", "emits a hollow scream as ribbons of essence", "Cast Roundtime", "Sing Roundtime", "You do not currently have a target", "wait (1|2|3)", "FUMBLE")
if line =~ /collapses into a heap of quivering jelly|motionless|shudders|going still|death overtakes|begins to dissolve from the bottom up|a plaintive wail before she slumps to her side and dies|emits a hollow scream as ribbons of essence|twitching for a moment before/
$slavedeath = true
elsif line =~ /(orc|troll|giant) (\w+) (rolls over|falls to the ground) and dies/
line.slice(/(orc|troll|giant) (\w+) (rolls over|falls to the ground) and dies/).join(", ")
$slavedeath = true
elsif line =~ /(\w+) gurgles|(.+) collapses/
line.slice(/The triton (.+) (gurgles|collapses)/).join(", ")
$slaveskintarget = $1
$slavedeath = true
end
sleep 3
elsif line =~ /YOU HAVE BEEN IDLE TOO LONG/
fput "exp"
elsif line =~ /player whispers(.+) mana/
put "send 100 gnimble"
else
sleep 0.25
end
end


This is the second.



while true
if $slavedeath == true
echo "THERELKEJR"
if $slaveskintarget =~ /radical|dissembler|magus/
put "skin #{target}"
if target =~ /radical/
$skin = "spine"
elsif target =~ /dissembler/
$skin = "claw"
elsif target =~ /magus/
$skin = "hide"
end
$slaveskintarget = nil
end
put "loot"
line = waitfor("You search", "only loot creatures", "not find a valid")
if line =~ /only loot creatures|not find a valid/
searched = true
$slavedeath = false
else
$slavedeath = false
searched = false
end
until searched
treasureline = waitfor("You gather the remaining", "You spy", "left (.+) behind", "(carried|had) (an?|some) .+ on", "(She|He|It) had (.+) (crystal-tipped|crystal-edged|crystal-studded) (longsword|mace|blade|fork|handaxe|broadsword)", "leaving nothing behind", "scattering and dissolving", "rapidly dissolving", "hideous scaled creature", "decays into compost", "cracks and collapses", "fissures quickly spread", "shudders and crumbles into itself", "crumbles away into dust")
if treasureline =~ /(carried|had) (an?|some) (.+) on/
treasure = $3
item = treasure.scan(/\w+/).last
elsif treasureline =~ /You gather the remaining/
$jink = true
elsif treasureline =~ /left (.+) behind/
treasure = $1
item = treasure.scan(/\w+/).last
elsif treasureline =~ /(She|He|It) had (.+) (crystal-tipped fork|crystal-edged (handaxe|broadsword|longsword|blade)|crystal-studded mace)/
treasure = $3
echo treasure
elsif treasureline =~ /You spy/
$heirloom = Array.new
obj = treasureline.split(/You spy|,/)
$heirloom = obj[1].scan(/\w+/).last
$specialobject = $heirloom
elsif treasureline =~ /crumbles away into dust|leaving nothing behind|scattering and dissolving|rapidly dissolving|hideous scaled creature|decays into compost|cracks and collapses|fissures quickly spread|shudders and crumbles into itself/
searched = true
treasure = nil
$heirloom = nil
else
treasure = nil
end
if $heirloom != nil
if !shieldworn
waitrt?
put "wear shield"
shieldworn = true
end
put "get #{$heirloom}"
put "stow #{$heirloom}"
end
if treasure =~ /crystal-tipped|crystal-edged|crystal-studded|strongbox|box|chest|trunk|coffer/
if !shieldworn
waitrt?
put "wear shield"
shieldworn = true
end
put "get #{treasure.scan(/\w+/).last}"
put "put #{treasure.scan(/\w+/).last} in gnimble disk"
put "stow #{treasure.scan(/\w+/).last}"
treasure = nil
$heirloom = nil
$box = true
elsif treasure =~ /(malachite|rhodochrosite|turquoise|morgandite|labr odite|banded sardonyx|adventureine) stone|green garnet|(white|a fire) opal|(golden beryl|bright chrysoberyl|aquamarine) gem|asterfire quartz|(black|grey) moonstone|blue starstone|jacinth|hyacinth|pale water sapphire|amber|spinel|carbuncle|obsidian|fire agate|tourmaline|(clear|pink|blue|smoky|golden) topaz|jasper|almandine garnet|diopside|cordierite|polished (blue|pink|red|black) coral|onyx|amethyst|bloodstone|deathstone|peridot| zircon|chalcedony|heliodor|(yellow|green|blue|blac k|pink|red) dreamstone/
if !shieldworn
waitrt?
put "wear shield"
shieldworn = true
end
put "get #{treasure.scan(/\w+/).last}"
put "put #{treasure.scan(/\w+/).last} in my coat"
elsif treasure =~ /ayanad crystal|hair|heavy quartz orb|(scratched|dented|corroded|shiny|tarnished|ben t|rusty|polished) (ring|fork|cup|plate|medallion|bracelet|fork|earri ng|anklet|spoon)|piece of iron|acantha leaf|coin|potion|ambrominas leaf|tattered cloth|haphip root|torban leaf|woth flower|ephlox moss|lichen|basal moss|sovyn clove|calamia fruit|brick|cupcake|doughnut|table leg|muffin|horseshoe|nail|white flask|smooth stone|tree bark|doorknob|cookie|bone|tart|cupcake/
elsif treasure != nil
if !shieldworn
waitrt?
put "wear shield"
shieldworn = true
end
put "get #{treasure.scan(/\w+/).last}"
put "stow #{treasure.scan(/\w+/).last}"
treasure = nil
$heirloom = nil
elsif $skin != nil
if !shieldworn
waitrt?
put "wear shield"
shieldworn = true
end
put "get #{$skin}"
if $skin =~ /claw|scale|spine|hide/
put "put #{$skin} in my cloak"
end
$skin = nil
end
end
if shieldworn
if $jink
put "tap my backpack"
$jink = false
end
put "remove shield"
if !checkleft("shield")
put "put #{treasure.scan(/\w+/).last}"
put "remove shield"
end
shieldworn = false
end
else
sleep 0.1
end
end

Shaelun
07-01-2008, 01:01 AM
If I have this right, you're trying to access the same global variable from two different instances of the program -- that doesn't work. Each program has its own environment. "Global" refers to "global within the current program's environment." Each instance has a different environment.

A year or two ago I wrote a script for a friend to use called "crosscharcom.lic" (Cross Character Communication), and I think it's still on the repository. It might be what you're looking for.

If that's not what you're trying to do, then you'll need to elaborate a little more on what's supposed to be going on (and what part of it isn't working right).

Danical
07-01-2008, 01:23 AM
Doh!

I have two slave characters attacking. During the attack routine as above (using 906) I check to see if the slave kills the creature. If it does, I want my primary to skin/loot/stow.

I tried using crosscharcom.lic but I couldn't seem to find a way to get it to do what I wanted.

Shaelun
07-01-2008, 01:53 AM
Well, if that's all you really want it to do, why not just have a script on your main that watches for something to die, then loots it when it does...?

What I'm getting at is -- achieving your goal doesn't require any communication between the characters, does it? Why not just have one guy killing the stuff with a script (or in this case both guys), and the observer just skinning whatever he sees die? If you don't feel like making it able to distinguish between your chars killing something and some random stranger killing it, just have it only loot when your guys are the only ones in the room.

All of this is assuming you weren't trying to stretch your skills and learn through doing, of course. If that's the case, then the only real method of two characters coordinating directly with eachother is through sockets (that's how crosscharcom.lic does it).

Without going too techie on you, I don't think there's a way to share memory between two processes in Ruby -- you'd have to be using a lower-level language (or find a Ruby wrapper for the mmap() syscall or something). I could always be wrong though.

Danical
07-01-2008, 02:06 AM
Ninja looting the kills of other players happens more often than I'd like hence my attempt to circumvent it.

I'll put a checkpcs line in there excluding my two slaves. We'll see how that works out.

Jaimaltz
07-01-2008, 03:12 AM
Is it possible to match multiple lines simultaneously with a regular expression? If so, that may be one way of doing it, as you could check to make sure it was your character that killed the creature and not someone else.

Another way is to write a script on the looting character to check the room for a dead creature immediately after every time your main attacks something.

I think the crosscharcom script can send commands, but can it tell another character to run a script too? You may be able to rewrite your main's script to call the crosscharcom script to tell your loot character to run the skin/loot/etc script.

Potentially another way is to set up your main script to perform a basic action (nod, grin, point to the critter corpse, whisper to your loot character, etc.) after successfully killing something, and have your loot character scripted to react to it and skin/loot as soon as they see that action.

That's all I could think of.

BigWorm
07-01-2008, 01:11 PM
Is it possible to match multiple lines simultaneously with a regular expression? If so, that may be one way of doing it, as you could check to make sure it was your character that killed the creature and not someone else.

Another way is to write a script on the looting character to check the room for a dead creature immediately after every time your main attacks something.

I think the crosscharcom script can send commands, but can it tell another character to run a script too? You may be able to rewrite your main's script to call the crosscharcom script to tell your loot character to run the skin/loot/etc script.

Potentially another way is to set up your main script to perform a basic action (nod, grin, point to the critter corpse, whisper to your loot character, etc.) after successfully killing something, and have your loot character scripted to react to it and skin/loot as soon as they see that action.

That's all I could think of.

I added something to my copy of crosscharcom to allow me to start scripts using it. Basically, to tell char2 to start a script, you would do > ;send to crosscharcom char2 ;script. I have aliases for most of that crap, so I usually do > char2 ;script.

My home internet connection is teh broken right now and I'm at work, but I'll try to remember to post that when I have a chance.

Danical
07-01-2008, 01:33 PM
I want it to be fully automated :(

I don't want to have even lift a finger for it if I don't have to.

What I got is working well enough now.

________________________________

HOWEVER, I can't seem to get checkgroup/group? to work. Any ideas?