|
Dasyr Newbie
Joined: 29 Jan 2016 Posts: 8
|
Posted: Sun May 29, 2016 4:42 am
2d Array |
Hi guys, I have read a fair few threads about this in the past but haven't had any luck so far figuring out how to get it to work.
I am attempting to use a 2d array to store some information for later in a script but I can't get it to work!
So far this is what I have..
This is the idea..
Code: |
#variable test {(one one|one two)|(two one|two two)} |
I can return them just fine..
Code: |
#say @test.1.1 - will return "one one"
#say @test.2.1 - will return "two one" |
The problem is when I go to edit them I can't figure out how to inset into a subset, I thought perhaps doing something like this would work but to no avail;
Code: |
#variable test %additem("one three",@test.1) |
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4689 Location: Pensacola, FL, USA
|
Posted: Sun May 29, 2016 1:59 pm |
It looks like you want to use a database variable.
Although the example you are using is rather too generic for me to discern what you actually want to do with it.
You switch from using to strings to numbers halfway through.
And your initial variable declaration is not in the proper format for a database variable.
you need a second dbVar just to help this one create itself
#VAR key {1=one|2=two|3=three|4=four|5=five}
Code: |
#LOOP 5 {
$this=%db(@test, %i)
#LOOP 5 {
$that=%db($this, %j)
$those=%concat(%db(@key, %i), " ", %db(@key, %j))
#ADDKEY $that %j $those
}
#ADDKEY test %i $this
} |
Something like that would populate the list to work as in your examples.
#SAY @test.3.4
should output "three four" |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Dasyr Newbie
Joined: 29 Jan 2016 Posts: 8
|
Posted: Sun May 29, 2016 3:14 pm |
Thanks for your reply shalimar, I am unfamiliar with how databases work, the portion of the script pertains to prospecting mines, ideally my intention was to have 3 sets of data, the direction, a weight for deciding which way to mine and a list of ores.
My main issue was not being able to manipulate the array in the way it is set up which I think is good enough for what I want to do, I found a way to do that using a temporary variable which will allow me to retrieve the data how I originally demonstrated (@var.1.1) - which should allow me to use #forall for the rest of the decision making, also this method so far hasn't put garbage in my variables, instead it's simply sent to the temporary variable if I decide to check a direction manually
Relevant code below;
Code: |
#alias prospect {#variable prospectDirections {};#forall {north|east|south|west|up|down} {#var prospectTemp %i;#additem prospectTemp 0;look %i;#wait 1500;#additem prospectDirections {(@prospectTemp)}}}
#alias addWeight {#col %1;#variable prospectTemp %additem(%2,@prospectTemp);#variable prospectTemp {%replaceitem(%eval(%item(@prospectTemp,2)+%3),2,@prospectTemp}}
#trigger { .. a fossilized dragon} {addWeight coral dragon 10000}
#trigger {Reinforced Mine lies to the north.} {addWeight grey mine -50}
#trigger {{endless abyss|darkness|vortex of darkness} lies (%w).} {addWeight crimson death -100000}
#trigger { .. a glowing ore deposit} {addWeight blueviolet mitrill 1000} |
which gives me
Variable: directionsPossible (north|-50|mine)|(east|0)|(south|0)|(west|0)|(up|0)|(down|10|ore)
#say @directionsPossible.1.2 > -50
If you can see a better way to do this let me know I'd be genuinely curious, |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4689 Location: Pensacola, FL, USA
|
Posted: Sun May 29, 2016 4:19 pm |
I just noticed we are in the zMUD forum.
Are you still using zMUD, or are you using the newer product CMUD? |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Dasyr Newbie
Joined: 29 Jan 2016 Posts: 8
|
Posted: Sun May 29, 2016 4:23 pm |
I am using zMUD 7.21, I tried CMUD and apart from some slight nuances with if checks I didn't notice much difference (except a few things about how it handles windows which made me ultimately stick with zMUD)
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4689 Location: Pensacola, FL, USA
|
Posted: Sun May 29, 2016 6:21 pm |
I would say your issue is how you are defining your database makes it so you have to rely on indirect references instead of direct references.
Most of your categories aren't even labeled.
Code: |
#alias prospect {
#variable prospectDirections {north|east|south|west|up|down}
#forall @prospectDirections {
#var prospectTemp %db(@prospectDirections, %i)
#ADDKEY prospectTemp Weight 0
look %i
#WAIT 1500
#addKEY prospectDirections %i @prospectTemp
}
} |
Code: |
#alias addWeight {
#col %1
#ADDKEY prospectTemp Notes %2
#ADDKEY prospectTemp Weight %eval(%db(@prospectTemp, "Weight")+%3)
} |
As for the benefits of CMUD...
#WAIT does not work properly in zMUD, but is fixed in CMUD.
And $local variables allow for saved space in your settings file.
dbVars are also converted to json, which allows for better control with deeper and deeper nesting arrays. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
|
|