I was wondering if you HAD to tie an else to an if that's why i asked about having to have the else at all.
Now about the different numbered returns. Do they go back to different locations?
I'm under the impression that a return bounced the script to the line after the gosub command. Since there are 16 different solutions that I need to include how would the script then know which one to send to? I can put an operation in there after every if that adds to the previous value. The total of the variable then tells the script where to look for the sub for the solution for that value.
If I did this I'd put a rule about clearing the count variable at the top of the script.
just out of curiosity will this be posted for public once it is completed? I would love a version of this. hehe.
Oh yeah this would definitely be a public script. I don't see anything gamebreaking with this little learning tool.
Ok...here's a little tutorial on how gosub's and returns work! It's a very simple example, but I am adding in a lot of features that kind of seem superfluous for something so basic, but it's just an example. I've added comments to almost every line to help you understand.
Here's a little sample:
;Variables
set %bandages ZLF
;Main loop
repeat
if #hits < #maxhits ;If you've taken damage
{
gosub CheckForSomething %bandages #backpackid ;First check for bandages in your backpack
if #result > 0 ;Then, if you have bandages, heal yourself!
{
gosub Heal
}
}
until #clilogged = 1 ;Main loop will repeat until you get disconnected or log out
sub CheckForSomething
finditem %1 C_ , %2 ;Checks for whatever is passed to it in slot 1, in a container specified by slot 2
return #findcnt ;Returns the number of bandages found
sub Heal
event macro 58 ;Bandage Self macro
return
Ok, let's take this one step at a time...
#1. I declare my variables. In this case, %bandages is set to ZLF which is the ItemTYPE for bandages (at least I'm pretty sure it is, I pulled it off the top of my head so I could be wrong)
#2. Our main loop! I almost always use a "repeat until" loop so that my script runs until I log out or get disconnected. Sometimes you may want to set some other conditions, but the repeat/until that I used in the example will almost always suffice!
#3. First we start by checking our hit points. If we are less than our max hit points, we then do something, in this case, check for bandages.
#4. Here's where things are a little more complicated! I call "gosub CheckForSomething %bandages #backpackid".
--Here's how the gosub works: When I call "gosub" I can pass it variables, in this case, %bandages and #backpackid. Once I'm in the subroutine, I can reference those variables by what "slot" they are in. If you hop down to the CheckForSomething sub, you'll notice I say "finditem %1". What this is actually saying is "finditem %bandages" since %bandages is the first thing I pass to the sub! The rest of that line reads "C_ , %2". This is the same as saying "C_ , #backpackid". Don't worry yourself with the meaning of the comma right now, it's a bit too complex (even for me sometimes). So, our line that reads "finditem %1 C_ , %2" is effectively the same as "finditem %bandages C_ , #backpackid". We are trying to find bandages in a specific container (our backpack).
#5. In our CheckForSomething sub, we then "return #findcnt". When we called the finditem command, it fills in a bunch of system variables for us: #findid, #findx, #findy, #findz, #findkind, #findmod, #findindex, #findtype, #findstack, #findrep, #findcnt, #finddist, #findbagid, and #findcol. Each of these gives us some information about whatever it found. The one that we are concerned about is #findcnt! This one tells us how many of our item it found! So in this case, how many bandages it found. We are then "returning" this value ("return #findcnt"). This puts the value of #findcnt into the #result system variable! We'll talk about this in the next step!
#6. Back up in our main loop, our next line is "if #result > 0". Now, we just put our value of #findcnt into the #result system variable, so that will tell us how many bandages if have. Therefore, this whole line is saying that if it found more than zero bandages, then heal yourself!
#7. Our Heal sub simply does event macro 58 (bandage self) and then returns. We do not pass it variables, and it does not return anything to us!
Ok, so you may be asking yourself WHY would I want to do this?! There are easier ways to do it! Well, the nice thing about a sub like "CheckForSomething" is that you can use it for ANYTHING! If you need to check for pots, just pass it %healpots or whatever else. And then specified which container you're looking for it in! Most of the time, it would be #backpackid, but you could look for something in a different container as well. You can also tweak it a bit! Maybe instead of returning it #findcnt, you can return #findid if it find something, or 0 if it doesn't! There's all kinds of fun things you can do!
So....back to the puzzles...What that sub in the script would do is return which puzzle it is in #result. Now, this is just one way to do it! You could alternately do something like:
sub PuzzlePicker
if (pixel=whatever)
{
gosub SolvePuzzle1
return
}
if (pixel=whatever)
{
gosub SolvePuzzle2
return
}
.
.
.
return
That way, it would solve the puzzle and then kick back out of the sub to continue the rest of the script!
I think I've written enough in this post, so I'll just end here. Keep posting any questions!