PDA

View Full Version : teaching myself ruby, need a hint



IorakeWarhammer
01-16-2011, 05:42 AM
need help with an easy project and a tougher project.

#1: need a script i can run in ruby that will simply loop the following:

fput "hide"
pause 5
fput "unhide"

dont know how to start the loop

#2:
im writing a script for a game that's similar to GS

here's what I need it to do: the character rests at the inn. the script will be him leaving the inn and entering a barracks. he will then alternate kick/attack on a training dummy. once his fatigue gets to exhausted, he will go to the bank, withdraw a little cash, then rest in the inn. while in the inn, he will order a bowl of stew and a piece of bread to recover his hunger. once his fatigue is gone, he will repeat the process. also, after he eats his food while resting, i want him to alternate hiding/unhiding. can be as simple as: fput hide, wait 5, fput unhide.

here's some details:

from inn to barrack (to begin hunt):

fput "out"
fput "n"
pause 1
fput "go barr"

once in barrack, he just needs to

fput "kill dummy"
pause 7
fput "kick dummy"
pause 5

until the message You are exhausted.. comes up

then he will go to the bank from the barrack, withdraw cash, and go into the inn:

fput "out"
fput "south"
pause 1
fput "west"
fput "go bank"
pause 1
fput "withdraw 13"
fput "out"
pause 1
fput "east"
fput "go inn"

from here, he will order a bowl of stew, and bread, and eat it..

fput "order 2"
fput "order confirm"
pause 1
fput "eat stew"
pause 1
fput "eat stew"
pause 1
fput "eat stew"
pause 1
fput "eat stew"
pause 1
fput "eat stew"
pause 1
fput "eat stew"
pause 1
fput "eat stew"
pause 1
fput "eat stew"
pause 1
fput "order 1"
fput "order confirm"
pause 1
fput "eat bread"
pause 1
fput "eat bread"
pause 1
fput "eat bread"
pause 1
fput "eat bread"
pause 1
fput "eat bread"
pause 1
fput "eat bread"
pause 1
fput "eat bread"
pause 1
fput "eat bread"

once this finishes, he will simply alternate hide / unhide, until his Fatigue: None (via health command) and then he will repeat the process

some helpful info:
when you type "health" it gives you the following

Current health: 100 Max health: 100
Fatigue: None Hunger: Well-Fed

and then..
fatigue comes in levels:
Levels of fatigue:
None
Winded
Tired
Exhausted

just need help with the strings and tying it all together.

to log in directly via an easy browser-based MUD client, just click:

http://clok.game-host.org/play/hmud/

you start in the town right near the inn. bank is one west of the inn, barracks are one north.

Blushy
01-16-2011, 09:59 AM
I'll give you a hint for #1:


loop {
fput("hide")
sleep(5)
fput("unhide")
}

It'd be even better if you had some sort of exit condition, though:


keep_hiding = true
while(keep_hiding == true) do
fput("hide")
sleep(5)
fput("unhide")
if(test_for_exit_condition() == true) then keep_hiding = false end
end

See if that gets you started.

IorakeWarhammer
01-16-2011, 10:58 AM
so that will run continually?

and in the 2nd one, in the if part, i would put any hiding fail message?

IorakeWarhammer
01-16-2011, 10:58 AM
derr

Alorn15
01-16-2011, 12:55 PM
You should read a basic ruby tutorial, at least the loop part will definitely be covered. I'd also look at regexes.

If you already have, you're more likely to get help if you show your work so far towards solving the problem.

Cephalopod
01-16-2011, 01:01 PM
http://hackety-hack.com/

subzero
01-16-2011, 04:24 PM
While we're on the topic... somewhere on here someone had custom ruby highlights (most notably they use a black background) for Notepad++ that I have lost and been unable to relocate. I'd appreciate it if anyone could direct me to them or toss'em up somewhere.

DaCapn
01-16-2011, 11:07 PM
Sleeping/pausing is strange in your first script. If you read the lich scripting API (on lichproject.org and on krakiipedia), you'll see that there are other useful functions (waitrt? in this case). The point of using ruby and lich is that you can call more powerful functions than you can with SF/wizard. (I guess there are two other points: the wizard interpreter hogs your CPU and you can only run one at a time). Granted this is a trivial task but if you want to learn it, actually do it or you'll never be able to raise the bar on what you can script and you'll always have bizarre hackery in wizard-minded scripts rather than elegant ones in ruby. Look at scripts on the repo as examples.

Obviously your other game will have limitations but doing something like this will put you on the right track:



def orderuse(item)
multifput "order #{item}","buy"
5.times { fput "use thing"; sleep 1 }
end
orderuse(1)
orderuse(2)

pabstblueribbon
01-16-2011, 11:18 PM
Oh goody I love a treasure hunt!

A wise man once said, if you want to learn the Lich scripting API, open up lich.rb in notepad++ and reverse engineer it with what you know, and scripts that make use of it.

My learning didn't really take off until I acquired the correct amounts of testicular fortitude and started breaking things. Later you'll progress into the bug the ever living fuck out of people for syntax or use, (thanks Tillmen), and with a little bit of guidance you will achieve padewan status and you can build a new lightsaber and all kinds of happy shit.

Remember what Yoda said, "Don't be bringing your bitch, to the waffle hut."

doughal
01-17-2011, 12:56 AM
Remember what Yoda said, "Don't be bringing your bitch, to the waffle hut."

Yoda was one wise motha!

pabstblueribbon
01-17-2011, 11:52 AM
Tunkalow parzen my brotha, tunka looow parzen.

IorakeWarhammer
01-17-2011, 12:47 PM
i'm using MUSHclient, can't seem to get the scripts to run. posting screenshots tonight

pabstblueribbon
01-17-2011, 12:52 PM
Do'h. You need to use a cracked version of Zmud. Google it.