Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ VBscript
➜ problems with array index across subs
problems with array index across subs
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Anssett
USA (9 posts) Bio
|
Date
| Thu 17 Jul 2003 08:12 AM (UTC) |
Message
| Ok - so, in the mud i play, one of the many things you can do is take goods from one 'tradepost' to another - and of course can check values before running so you can pick and choose more profitable runs.
i currently have an array of the goods that can be valued, and a script that runs through that array and does the value command for each (eg. "value pearls") - unfortunately, i'm having trouble actually storing the value per item via a trigger. i think the problem is, the script outputs all of the value statements before the mud processes them, so i lose the current index in the array , and the mud response does not include the good's name, but the container it's packed in, so i can't go through the array and compare by that.
having said all that - here's what i have so far, forgive the junky code please :P
first i have:
public tradeArr(87,4) - this holds, among other things, the goods names (col 0), the maximum number that will fit in a wagon (col 1), the trade post they are located (col 3), and in theory, the value per item (col 2) and the product of columns 1 and 2 (held in column 4). as far as i can tell, the columns that are static (0,1,and 3) are just fine, so i don't think my problem stems directly from an array problem.
after this, i have code that runs through the array, pulls the goods name from it and sends the trade command to the mud. this is just a simple loop that works quite well :P
i also have a trigger that is set to respond to the mud's output when it recieves the value command:
the output: We will pay you 1234 gold for each case.
note that the 1234 and 'case' vary from good to good
my trigger:
<trigger
enabled="y"
match="We will pay you * gold for each *."
send_to="10"
sequence="100"
other_text_colour="black"
other_back_colour="black"
>
<send>/setVal %1</send>
</trigger>
the setval script is well, an attempt to make use of a global counter and write to the array. it failed. i just have the script reporting the gold to world.note at the moment, which it does quite well...
basically what i need is a way to write the gold to the array in the proper place. any input is of course welcome, let me know if you need to see some/all of my code, i don't want to spam the message after such a lengthy explanation :P
-ans |
---
a world without cheese would be a sad world indeed | Top |
|
Posted by
| Meerclar
USA (733 posts) Bio
|
Date
| Reply #1 on Thu 17 Jul 2003 08:51 AM (UTC) |
Message
| To actually troubleshoot code, we will need to see what yer working with otherwise its all guesswork and may be completely incomopatable with what you already have in place. In short, post it all so we can see what's goin on and how to possibly fix your problem. |
Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org | Top |
|
Posted by
| Poromenos
Greece (1,037 posts) Bio
|
Date
| Reply #2 on Thu 17 Jul 2003 12:01 PM (UTC) |
Message
| Can't you just have a global counter that adds goods in order? For example, if you do "value one" "value two", i would think that the MUD would return the value of "one" and then the value of "two". Just make the function store the prices in the order they were valued.
Alternatively, you can have the array store each value in a variable, and do something in the MUD, such as a say. Sample output:
>value one
>say valued one
>value two
>say valued two
We will pay you 12938 coins for each case.
You say 'valued one'
We will pay you 32423 coins for each case.
You say 'valued two'
So, when you get "we will pay you", you store the price in a variable, and when you get the "say" line, you get the object name and store it in the array, along with the last price you saw. |
Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it! | Top |
|
Posted by
| Anssett
USA (9 posts) Bio
|
Date
| Reply #3 on Thu 17 Jul 2003 02:58 PM (UTC) |
Message
| ok, point taken about the code :P
here goes:
public tradeArr(87,4) 'the trade array
public iIndex 'an attempt at a global index variable
sub tradeInit()
'this sub just populates the array. including the name for continuity :P
end sub
sub valAll()
'this is the sub that loops through the array, doing the values
'makes use of iIndex
dim strVal, strValMe
iIndex=0
do
strValMe = tradeArr(iIndex,0)
strVal = "value " & strValMe
world.execute strVal
'world.note "strVal=" & strVal & " iIndex=" & iIndex
world.note "tradeArr(iIndex,2) = " & world.getVariable("currVal")
iIndex = iIndex + 1
loop until iIndex > (uBound(tradeArr,1))
end sub
sub setVal(iIn)
'this sub reports to the screen what the amount is per item
'i've put the iIndex in the world.note before, and it is always 88.
dim iAmount
iAmount = iIn
world.setVariable "currVal",iAmount
world.note "iAmount="&iAmount
end sub |
---
a world without cheese would be a sad world indeed | Top |
|
Posted by
| Anssett
USA (9 posts) Bio
|
Date
| Reply #4 on Thu 17 Jul 2003 03:01 PM (UTC) |
Message
| poromenos - while that may or may not work, it's not really an option. a method like that will be quite spammy, to me and to other people that are around.
when i get off work today, i'll show you guys an abbreviated version of the output of this script.
-ans |
---
a world without cheese would be a sad world indeed | Top |
|
Posted by
| Anssett
USA (9 posts) Bio
|
Date
| Reply #5 on Thu 17 Jul 2003 08:42 PM (UTC) |
Message
| here's what happens running this, i just pasted the first 10 to save space.
value ale
strVal=value ale iIndex=0
value tar
strVal=value tar iIndex=1
value salt
strVal=value salt iIndex=2
value sugar
strVal=value sugar iIndex=3
value raisins
strVal=value raisins iIndex=4
value flowers
strVal=value flowers iIndex=5
value arrows
strVal=value arrows iIndex=6
value bows
strVal=value bows iIndex=7
value art
strVal=value art iIndex=8
value parchment
strVal=value parchment iIndex=9
We will pay you 80 gold for each barrel.
iAmount=80 iIndex=88
[DH]<976hp 132m 610mv 100br> We will pay you 120 gold for each barrel.
iAmount=120 iIndex=88
[DH]<976hp 132m 610mv 100br>
We will pay you 80 gold for each sack.
iAmount=80 iIndex=88
[DH]<976hp 132m 610mv 100br>
We will pay you 110 gold for each sack.
iAmount=110 iIndex=88
[DH]<976hp 132m 610mv 100br>
We will pay you 60 gold for each basket.
iAmount=60 iIndex=88
[DH]<976hp 132m 610mv 100br>
We will pay you 570 gold for each crate.
iAmount=570 iIndex=88
[DH]<976hp 132m 610mv 100br>
We will pay you 324 gold for each bundle.
iAmount=324 iIndex=88
[DH]<976hp 132m 610mv 100br>
We will pay you 568 gold for each bundle.
iAmount=568 iIndex=88
[DH]<976hp 132m 610mv 100br>
We will pay you 770 gold for each crate.
iAmount=770 iIndex=88
[DH]<976hp 132m 610mv 100br>
We will pay you 30 gold for each ream.
iAmount=30 iIndex=88
so i think, if i can make the trigger fire before proceeding to the next value, then i'll be good....i just don't know how to go about doing that.
-ans |
---
a world without cheese would be a sad world indeed | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #6 on Thu 17 Jul 2003 10:43 PM (UTC) |
Message
| Your problem is what you suspected - the script sends a whole lot of lines - the MUD may not reply for a second or so. Do you have something like a "think" command that lets you say something to yourself only? Thus you might say:
think fish
value fish
think sword
value sword
Then the MUD replies:
You think, "fish"
We will pay you 80 gold for each barrel.
You think, "sword"
We will pay you 100 gold for each crate.
Then you know which is which. You could make the "think" command "omit from output" so it doesn't spam you.
However a simpler solution would be to simply count the responses. Say you do 10 values, like this:
value ale
value tar
value salt
value sugar
value raisins
value flowers
value arrows
value bows
value art
value parchment
Now, the responses are going to come back in order aren't they? So, as you send out the value commands you set a global variable to zero.
Then as the trigger gets each response:
We will pay you * gold for each *.
You simply compare to the nth item in the array and then add 1 to n.
ie.
We will pay you 80 gold for each barrel.
' <-- item zero, must be ale, now add 1
We will pay you 120 gold for each barrel.
' <-- item 1, must be tar, now add 1
We will pay you 80 gold for each sack.
' <-- item 2, must be salt, now add 1
and so on.
You probably want to build in a check that the value is in range (in case you value something manually), or disable the matching trigger once you have processed all 10 items.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #7 on Thu 17 Jul 2003 10:44 PM (UTC) |
Message
| When I re-read this thread I see I am saying what Poromenos did, in a lengthier way. :) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Anssett
USA (9 posts) Bio
|
Date
| Reply #8 on Thu 17 Jul 2003 10:51 PM (UTC) |
Message
| ahhh i see what you mean
i misunderstood what poromenos said i think.
i don't know why i didnt think to just start the loop over again, i guess i'm just dense or something :P
we'll see if i can make it work now
-ans |
---
a world without cheese would be a sad world indeed | Top |
|
Posted by
| Magnum
Canada (580 posts) Bio
|
Date
| Reply #9 on Thu 17 Jul 2003 11:43 PM (UTC) |
Message
| Personally, I would take a different approach. In pseudo-code:
1. Set index to 1
2. Output request to capture required information.
3. On reception of information, store information.
4. Increase index counter by one.
5. Go to step 2.
I would create an alias to start the process, and another to stop, in case you want to abort early. At step 2, you would check a flag to see if you should continue or not. Also, although it would greatly lengthen the process, I might add a 1 second timer to step 2, to allow for processing of of other mud output and reduce my "spamming" of the mud.
In other words:
Ask?
Receive.
Ask?
Receive.
As opposed to:
Ask?
Ask?
Receive.
Receive. |
Get my plugins here: http://www.magnumsworld.com/muds/
Constantly proving I don't know what I am doing...
Magnum. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #10 on Fri 18 Jul 2003 06:11 AM (UTC) |
Message
| Yes, that would work pretty well, in other words each trigger response causes the next one to be valued. However that is probably a bit slower, as you have (say) a 1-second response for the server to respond, so it might be 10 seconds to get the lot. Of course, you might get the 10-second delay anyway, depending on how the server is written. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
27,860 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top