Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot change values wuth ImGui #88

Open
sinaSPOGames opened this issue Oct 21, 2024 · 4 comments
Open

cannot change values wuth ImGui #88

sinaSPOGames opened this issue Oct 21, 2024 · 4 comments

Comments

@sinaSPOGames
Copy link

sinaSPOGames commented Oct 21, 2024

i use this following code to change some values that will be important for me to debug on

var player = null
func _DEBUG_UI(delta):
	if player != null:
		ImGui.Begin("DEBUG_GUI")
		ImGui.DragFloat("Vehicle Dirtyness", [player.dirtyness])
		ImGui.DragFloat("Vehicle Engine Health", [player_health_engine])
		ImGui.DragFloat("Vehicle Body Health", [player_health])
		ImGui.End()

the problem is none of these values do change no matter what i do, those values arent controlled by anything else unless there is some circumstances for example engine health reduces only if my player's vehicle goes over its RPM capacity (an V8 going over 10krpm)

no matter what i do those values never change

@pkdawson
Copy link
Owner

See #73 (comment)

I really need to reorganize and expand the docs to clarify some common issues.

@sinaSPOGames
Copy link
Author

sinaSPOGames commented Oct 22, 2024

I found out my way out with this method tho

var imgui_value_number := [something]

In function:
   ImGui.dragfloat("something", imgui_value_number)
   If GameManager.Brute_Update:
      My_actual_value = imgui_value_number[0]

This is kinda something but good enough for me
This can be helpful for those who can't modify their var to be array since that variable is possibly being used by alot of code making the things harder for them

@axel37
Copy link

axel37 commented Nov 5, 2024

I faced a similar issue while trying to set up a debug menu.

Here, I'm trying to update a variable stored in a Global autoload.
It seems that setters aren't called :

var menu_is_open: bool = false

var debug_overlay_enable = [false]:
	set(value):
                # This is never reached
		print("Changing value..."])
                # "Global" is an autoload
		Global.game_settings.debug_overlay_enable = value[0]
		debug_overlay_enable = value


func _input(event: InputEvent) -> void:
	if event.is_action_pressed("open_debug_menu"):
		menu_is_open = not menu_is_open


func _process(_delta: float) -> void:
	if menu_is_open:
		ImGui.Begin("Debug menu")
		ImGui.Checkbox("Enable debug overlays", debug_overlay_enable)
		ImGui.End()

As suggested by @sinaSPOGames, manually updating the variable works, but is not very elegant :

extends Node

var menu_is_open: bool = false

var debug_overlay_enable: Array = [false]

# func _input [...]

func _process(_delta: float) -> void:
	if menu_is_open:
		ImGui.Begin("Debug menu")
		ImGui.Text("Hello world !")
		ImGui.Checkbox("Enable debug overlays", debug_overlay_enable)
		ImGui.End()

	        Global.game_settings.debug_overlay_enable = debug_overlay_enable[0]

... and it still requires creating a variable.

It would be great to have an easier way of binding the value of ImGui controls to existing variables !

(and I'm glad you're considering improving the docs, that's always appreciated)

@sinaSPOGames
Copy link
Author

one thing can be done is adding a unique way to access variables

in imgui's base code instead of requiring the ImGui.example(example, example[0]) just do the second identifier in code
it can check wether its a normal variable or just an array, if normal variable then convert it into a unique array variable and use that to set the actual variable, by this way we dont have to creating a variable just for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants