Hello, Fred,
the following problem occurs only with SpiderBasic, but not with PureBasic. The sample code should run in both development envorinments because of the identical command set.
I suspect that the not working in SpiderBasic is a bug and not a missing feature or something else.
Sorry that the demo code is a bit more complex, but it reflects exactly the problem in my real project.
There is a structure "house" with several "rooms" and the "roomitems" contained in rooms. Each item has an integer value and a string value which are stored directly at the item.
Additionally there is a structure "storage" which also contains integer values. All structures work with maps.
In the ForEach loop all items are processed and checked if the roomitem string value is filled. If it is not filled, the variable "MyValue" is set with the integer value of the item. Otherwise the string value of the item is used as a MapKey for the structure "Storage".
In this case the integer value is determined from the map "mpStorage" and written to "MyValue". This type of access should actually work in a single line:
Code: Select all
MyValue = *House\mpStorage(\mpRoomItem()\sRoomItemValue)\iStorageValue
Under SpiderBasic I have to use a second string variable 'RefKey' as temporary storage:
Code: Select all
RefKey = \mpRoomItem()\sRoomItemValue
MyValue = *House\mpStorage(RefKey)\iStorageValue
Democode:
Please notice, you first have to tweak the CompilerIf to see the problem!
Code: Select all
EnableExplicit
Structure structStorage
iStorageValue.i
EndStructure
Structure structRoomItem
iRoomItemValue.i
sRoomItemValue.s
EndStructure
Structure structRooms
iRoomValue.i
sRoomValue.s
Map mpRoomItem.structRoomItem()
EndStructure
Structure structHouse
Map mpStorage.structStorage()
Map mpRooms.structRooms()
EndStructure
Global *House.structHouse, *Room.structRooms, RefKey.s, MyValue.i
*House = AllocateStructure(structHouse)
If *House <> 0
*House\mpStorage("ST1")\iStorageValue = 33
*House\mpStorage("ST2")\iStorageValue = 44
*House\mpStorage("ST3")\iStorageValue = 55
*House\mpRooms("LivingRoom")\mpRoomItem("Desk")\sRoomItemValue = ""
*House\mpRooms("LivingRoom")\mpRoomItem("Desk")\iRoomItemValue = 10
*House\mpRooms("LivingRoom")\mpRoomItem("Table")\sRoomItemValue = ""
*House\mpRooms("LivingRoom")\mpRoomItem("Table")\iRoomItemValue = 11
*House\mpRooms("LivingRoom")\mpRoomItem("Cabinet")\sRoomItemValue = "ST1"
*House\mpRooms("LivingRoom")\mpRoomItem("Cabinet")\iRoomItemValue = 12
*Room = FindMapElement(*House\mpRooms(), "LivingRoom")
With *Room
ForEach \mpRoomItem()
Debug "Int Value of RoomItem " + MapKey(\mpRoomItem()) + ": " + \mpRoomItem()\sRoomItemValue
If \mpRoomItem()\sRoomItemValue = ""
MyValue = \mpRoomItem()\iRoomItemValue
Else
CompilerIf #PB_Compiler_Processor = #PB_Processor_JavaScript
; Workaround for SpiderBasic
RefKey = \mpRoomItem()\sRoomItemValue
MyValue = *House\mpStorage(RefKey)\iStorageValue
CompilerElse
; In PureBasic this works like expected
MyValue = *House\mpStorage(\mpRoomItem()\sRoomItemValue)\iStorageValue
CompilerEndIf
EndIf
Debug "Str Value of RoomItem " + MapKey(\mpRoomItem()) + ": " + Str(MyValue)
Next
EndWith
FreeStructure(*House)
EndIf