Skip to content

Instantly share code, notes, and snippets.

@Structed
Created December 28, 2022 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Structed/2edc3644e42d3085797d08241ffa96d6 to your computer and use it in GitHub Desktop.
Save Structed/2edc3644e42d3085797d08241ffa96d6 to your computer and use it in GitHub Desktop.
Godot Engine reproduction for str2var/var2str with multi-dimensional objects
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )
extends Control
func _on_Var2TextButton_pressed():
var test = {
"level": "one",
"second": {
"level": "two"
}
}
var text = var2str(test)
$VBoxContainer/TextEdit.text = text
func str_to_var(text: String):
var v = str2var(text)
return v # Debug breakpoint here
func _on_Text2VarButton_pressed():
str_to_var($VBoxContainer/TextEdit.text)
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Main.gd" type="Script" id=1]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="TextEdit" type="TextEdit" parent="VBoxContainer"]
margin_right = 1024.0
margin_bottom = 200.0
rect_min_size = Vector2( 0, 200 )
[node name="Var2TextButton" type="Button" parent="VBoxContainer"]
margin_top = 204.0
margin_right = 1024.0
margin_bottom = 224.0
text = "Var to text"
[node name="Text2VarButton" type="Button" parent="VBoxContainer"]
margin_top = 228.0
margin_right = 1024.0
margin_bottom = 248.0
text = "Text to var"
[connection signal="pressed" from="VBoxContainer/Var2TextButton" to="." method="_on_Var2TextButton_pressed"]
[connection signal="pressed" from="VBoxContainer/Text2VarButton" to="." method="_on_Text2VarButton_pressed"]
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
[application]
config/name="repro"
run/main_scene="res://Main.tscn"
config/icon="res://icon.png"
[display]
window/stretch/mode="2d"
window/stretch/aspect="keep"
[gui]
common/drop_mouse_on_gui_input_disabled=true
[physics]
common/enable_pause_aware_picking=true
[rendering]
environment/default_environment="res://default_env.tres"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment