Does the Multi-Dimensional map exist?

I am trying to use a multi-dimensional map.

var AllAgentsShopBeacons : [agent][int]?beacon_device = map{}

The code does not show any error, but when I try to change the value, I can´t

loop:
            if(MaybeBeacon := AllAgentsShopBeacons[Agent][Index], MaybeBeacon = false?, set AllAgentsShopBeacons[Agent][Index] = Beacon):
                break

ANy ideas?

Hey, when i have tried to use Multy-Dimensional map i could also not set the value when i used

set AllAgentsShopBeacons[agent][int] = Beacon

A work around could be to first get the map the agent is key to. Then you could make a copy of that map as a varible and set index as key to the Beacon value. Then at last save that map as value to AllAgentsShopBeacons[agent]

if AllAgentsShopBeacons[agent] dont have a map you could create a new map and set it to it.

here is a example i just tested where when i tried to check AllAgentsShopBeacons[agent][int] i got a value.

# Changed the types so it would be easier to test
var AllAgentsShopBeacons : [string][int]float = map{}
Agent := ""
Index :int= 0
Beacon := 1.0

# Loop break
var counter :int = 0
loop:
    if (counter = 10):
        Print("No beacons found")
        break
    
    if:
        Col := AllAgentsShopBeacons[Agent]
        var new : [int]float = Col
        set new[Index] = Beacon
        set AllAgentsShopBeacons[Agent] = new
    then:
        break
    else if:
        not AllAgentsShopBeacons[Agent]
        new : [int]float = map{Index => Beacon}
        set AllAgentsShopBeacons[Agent] = new
    then:
        break
    
    set counter = counter + 1
  
# To Test
if(Val := AllAgentsShopBeacons[Agent][Index]):
    Print("Beacon found {Val}")      # Output = Beacon found 1.000000
else if(not AllAgentsShopBeacons[Agent][Index]):
    Print("if work but no beacon found")
else:
    Print("Beacon not found")
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.