How do you assign a value to a map of structs?

It seems you can’t assign a value to a map of structs because the compiler thinks you want to modify the interior of the struct instead of replacing the struct wholesale in the map:

example_struct := struct:
  something: int

example := class:
  ExampleMap: [int]example_struct := map{}

  Test():void =
    if(set ExampleMap[0] = example_struct{something:= 0}):

The above code will error on the last line with The assignment's left hand expression type 'example_struct' cannot be assigned to(3509). It’s an odd error, since the struct does not exist yet in the map, seems like a type system problem.

Any ideas how to work around this?

Ah, the error was rather confusing, but the actual problem here is that the Map is defined as constant and not var, this works:

example_struct := struct:
  something: int

example := class:
  var ExampleMap: [int]example_struct := map{}

  Test():void =
    if(set ExampleMap[0] = example_struct{something:= 0}):

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