B4J Question Thread safe map error

(I don't think I have to create a new thread for this, it seems to be related to the same thing)

Trying to get the values added to a "thread safe map":

MAIN
Code: Copy
Sub Process_Globals
    Public srvr As Server
    Public mapGameRooms As Map
End Sub

Code: Copy
Sub AppStart (Args() As String)
...
    mapGameRooms = srvr.CreateThreadSafeMap
    For r = 0 To 4
        Dim GameRoom As clsGameRoom
        GameRoom.Initialize
        Dim GameRoomName As String = "Room " & r
        GameRoom.Name = GameRoomName
        mapGameRooms.Put(GameRoomName, GameRoom)
    Next

    StartMessageLoop

End Sub


Websocket class
Code: Copy
Private Sub RunOnClient_SendRoomsList(Msg As String)

    Dim lst As List
    lst.Initialize

    Dim GameRoom As clsGameRoom

    For r = 0 To Main.mapGameRooms.Size - 1

        GameRoom = Main.mapGameRooms.Get(r)
        If GameRoom <> Null Then
            lst.Add(GameRoom.Name)
        Else
            Log("GameRoom is null")
        End If

    Next

    ws.RunFunction("FromServer_Rooms", lst)
    ws.Flush

End Sub

GameRoom is always Null
 
Last edited:
Upvote 0
Should you not use
Code: Copy
    GameRoomName = Main.mapGameRooms.GetKeyAt(r)
or
Code: Copy
    GameRoom = Main.mapGameRooms.GetValueAt(r)
Depending on if you want the name string or the actual room
 
Upvote 0
The comments for Server.CreateThreadSafeMap make it clear that the Map created by this function doesn't support Map.GetValueAt and Map.GetKeyAt nor does it preserve the order of the elements.
 
Upvote 0
The comments for Server.CreateThreadSafeMap make it clear that the Map created by this function doesn't support Map.GetValueAt and Map.GetKeyAt nor does it preserve the order of the elements.

I stand corrected, I was just going by the assist that pops up. Plus Lucas used ...get(r) so it could have been a typo.
 
Upvote 0
Back
Top