-1

test my exemple code: https://go.dev/play/p/G7LxjDNjNAn

terminal result:

&{0}
&{1}

how i want output from example terminal

&{1}
&{1}

my code in project:

func Set(recv *Value, value Value) {
    reflect.ValueOf(recv).Elem().Set(reflect.ValueOf(value))
}

func (this *SetBlock) On_Exec(locals map[string]Value) {
        //this.inputs["Recv"].Value is pointing to the same value as global
    if this.inputs["Recv"].Value != nil {
        Set(&this.inputs["Recv"].Value, this.inputs["Value"].Value.Copy())
    }
        //this.layer.Game.Globals() is a original
        fmt.Println(this.layer.Game.Globals())
    this.outputs["After"].Value = Create_Bool(true)
}

I'm here because I don't even know how to research this.

have change in A and B. whoever helped me with the "Set" function sent a code. Hope you send too. For some reason it worked, now it doesn't.

I can't assign to the map, because this function was made in such a way that I cannot even know if the value comes from an array if it is a variable or a map tag

the "Set" function works for different types https://go.dev/play/p/TggxPxF5kx9

one way i'm sure would work is to create a pointer pointer, not being a map pointer, a pointer that points to the pointer that points to the value of the 2 maps

the "Set" function is based on setting the pointer to the other pointer. I think the error is that I'm pointing to the wrong pointer

kaklik
  • 11
  • 2
  • 3
    Aside from the incorrect assignments and pointer indirections (you don't want `*any` here), you are never going to be able to assign a `B` value to an `A` value. They are different types. If you want to set a map value via reflection, you need to reflect on the map, not a pointer to a value which is also contains in a map. – JimB Mar 09 '23 at 21:38
  • See also [why-does-go-forbid-taking-the-address-of-map-member](https://stackoverflow.com/questions/32495402/why-does-go-forbid-taking-the-address-of-map-member-yet-allows-slice-el) – colm.anseo Mar 09 '23 at 23:38
  • 1
    No, your `Set` function does not work for different types, it’s using `*any` as the type. This could work if you used `*any` in the map, but that is probably not what you want to do. – JimB Mar 10 '23 at 03:31
  • (it would be easier to respond if you did so in the comments, and added the code to the question, especially when you change the original question being asked). The error was that you are expecting to set the wrong type, that is all. You can't just keep adding pointers and expect the type to go away, `***A` is still a different type from `***B`, more layers of indirection is not what you need. Your latest version is using 2 different `*C` values, so of course updating one is not going to update the other. – JimB Mar 10 '23 at 13:38

1 Answers1

0

I conceived, when creating the value I create two pointers to that value, that is ** and that way to change. thanks: @JimB

kaklik
  • 11
  • 2