#How do I make separate conditional tool scripts share/call things between each other?

6 messages · Page 1 of 1 (latest)

plush pecan
#

Hi guys, how do I go about running a conditional tool script in two scripts so they could call each other? I have them both working separately with editor check and safeguard bool check under their respective _process but I can't figure out how to share data between them to process.

My first instinct was to have functions I want to call nested under the _process but it doesn't seem like this is allowed. I've been stuck on this and I'm out ideas and internet search keywords.

This is how I've been testing and debugging my scripts so far when the logic was contained to a single script and it's instances:

`@export var editor_code_execution: bool = false

func _process(delta: float) -> void:
if Engine.is_editor_hint() and editor_code_execution:
print("Hello")
editor_code_execution = false`

But now that I want to expand the scope of my project I have problems coming up with a way to make things work. Is there a solution that I missed or failed to consider? For context I'm trying to learn working with resources so one scripts belongs to a resource and the second one belongs to a template that I'm building for something.

tranquil portal
#

Signals, maybe?

signal something(some_data)

func my_action():
  print("action!")
  something.emit("hello")
plush pecan
#

You need a function to collect a signal, no? The issue is that I can't use a function (I think) because the editor script can run only under _process function. For now though I switched to learning something else because I couldn't figure it out. I think my approach for debugging in general was bad because I tried to do things through the editor and not the project itself. After I'm done with the thing that I'm working on I will look into runtime debugging. Being able to make whole user interfaces instead of forcing things into the inspector will make things easier on the convenience level but idk how it will work out in practice yet.

tranquil portal
#

It's hard to give an answer without knowing the details - what are the tools doing that requires it to be _process()?

plush pecan
# tranquil portal It's hard to give an answer without knowing the details - what are the tools doi...

TLDR: I'm just confused about when the code can be executed and called using tool in the editor.

Run the code for called functions when specific conditions are met. Currently they are to 1. be in editor and 2. have a toggle (bool) true. The code for those checks is included in the post. But now that I remembered that I made this post and checked it again to see if anyone responded I realised that I may have incorrectly assumed how tool and engine hints work. I think it could work if I simply added that "if engine." under any function to make it callable without the code to be required under process. Originally I thought that if part of the script that's being processed in editor calls the other part (a function for example) that isn't then it would make it run in the editor too as the extension of it which wasn't the case. I can't check it right now because I'm in the middle of working on something and I don't want to lose track of what I was doing.

tranquil portal
#

There's not really a hard limit on what's allowed to be called in-editor.

In edit-time, everything's waiting for an event. Mouse, keyboard, a property change...
The _process(delta) function works as long as the script is attached to a node that's within the scene tree.

Resources have their changed() event for whenever a property is updated

@tool
class_name MyResource
extends Resource

@export var prop: int:
  get: return prop
  set(value):
    if prop != value:
      prop = value
      emit_changed()

All the built in resources and the editor uses changed() to keep track, I think.

@tool
extends Node

@export var res: MyResource:
  get: return res
  set(value):
    if res != null: res.changed.disconnect(_on_res_changed)
    res = value
    if res != null: res.changed.connect(_on_res_changed)

func _on_res_changed():
  print("changed")