英文:
set value of map1 and map2 through a reflector pointer
问题
测试我的示例代码:
https://go.dev/play/p/G7LxjDNjNAn
终端结果:
&{0}
&{1}
我希望从示例终端输出:
&{1}
&{1}
我的项目中的代码:
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指向与全局变量相同的值
if this.inputs["Recv"].Value != nil {
Set(&this.inputs["Recv"].Value, this.inputs["Value"].Value.Copy())
}
//this.layer.Game.Globals()是原始值
fmt.Println(this.layer.Game.Globals())
this.outputs["After"].Value = Create_Bool(true)
}
我来这里是因为我甚至不知道如何研究这个问题。
在A和B中有所改变。
帮助我编写"Set"函数的人发送了一段代码。
希望你也能发送一段代码。
由于某种原因,它之前起作用,现在不起作用了。
我无法对map进行赋值,
因为这个函数是这样设计的,我甚至无法知道值是来自数组还是变量或映射标签。
"Set"函数适用于不同的类型。
https://go.dev/play/p/TggxPxF5kx9
我确定的一种方法是创建一个指针指针,而不是一个映射指针,
一个指向指向两个映射值的指针的指针。
"Set"函数基于将指针设置为另一个指针。
我认为错误在于我指向了错误的指针。
英文:
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
答案1
得分: 0
我在创建值时,构思了两个指向该值的指针,即 ** ,这样可以进行更改。谢谢:@JimB
英文:
I conceived, when creating the value I create two pointers to that value, that is
**
and that way to change.
thanks: @JimB
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论