[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  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] Refresh page


Posted by Anssett   USA  (9 posts)  [Biography] 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
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] 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
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] 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!
[Go to top] top

Posted by Anssett   USA  (9 posts)  [Biography] 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
[Go to top] top

Posted by Anssett   USA  (9 posts)  [Biography] 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
[Go to top] top

Posted by Anssett   USA  (9 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] 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
[Go to top] top

Posted by Anssett   USA  (9 posts)  [Biography] 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
[Go to top] top

Posted by Magnum   Canada  (580 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] 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
[Go to top] 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.


23,140 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]