PDA

View Full Version : Learning to Write Basic Scripts



Neparr
03-06-2014, 02:36 PM
I was playing around with writing a basic script for shattered that will ask for Alfred to make some bread while I'm burning down in TSC and castings buffs.

The intent is to have it look and see if Alfred is in the room. If he is then ask for some bread and grab it when it drops. That part works fine. I also want to add a little redundancy to it such that. If he is not in the room instead of ending the script like it does now it waits a certain amount of time and checks again. Lets say it waits 15 seconds between checks. If Alfred is in the room but otherwise engaged in an activity and is unable to make bread at that time it wont get hung up looking for the bread to be dropped and instead times out from the waitfor after say 30 seconds. In this case the script could just end so that it isnt getting hung up. I tried to establish a label that i could use as a reference for a goto command to bound back to the top of the script. My attempt looked like so. Any thoughts from the experienced writers out there. I'm still very new at this but i imagine i will pick it up quickly. Still learning arrays.

label 'MainLabel'
if checkpcs.include?('Alfred')
fput 'whisper alfred bread'
waitfor "Alfred drops a spinach-paste steamed dumpling."
multifput "get dumpling", "gobble my dumpling", "gobble my dumpling", "gobble my dumpling"
else
pause '15s'
goto 'MainLabel'
end

SpiffyJr
03-06-2014, 06:22 PM
Avoid labels and use proper loops instead.



while true
if checkpcs.include?('Alfred')
# the 30 here is the time to wait for the response in the third part
res = dothistimeout 'whisper alfred bread', 30, /Alfred drops a .*\./
if res.nil?
# unknown result (alfred didn't make bread)
# do what you want here
else
# alfred made bread
multifput "get dumpling", "gobble my dumpling", "gobble my dumpling", "gobble my dumpling"

# the break says "exit the loop" which will effectively end the script
break
end
end

# you need some sleep delay in loops to avoid maxing our your CPU
sleep 0.25
end

subzero
03-07-2014, 05:26 AM
restbread-gsf should be on the repo and work for that purpose. I'm not playing anymore, so it won't get updated for newer bots, but it wouldn't be hard to add to it.

Neparr
03-08-2014, 10:51 AM
Thank you for the advice. I take it the labels command doesn't work as well as just making a loop. I will remember that and use that for future scripts.

Thank you as well for the alternate bread script. I didn't realize their was already on the repo.