Pass data between files (coblock and typescript)

my idea is literally this: Getting cospaces properties from coblocks into scripts

can someone solve that?

basically the concept is:

  1. create variable inside coblock
  2. read variable inside typescript
  3. change variable in typescript
  4. read variable in codeblock
    … and viceversa.

from what I saw, the block that we can use is:

but it didn’t work

1 Like

:eyes: we still need your help…

I am the same autor who asked, now I am trying to show all the things I found/learnt about this, until I solve the problem.

once solved, I will update the H1 title with “solved”, so for now If you any idea on how to solve, feel free to partecipate to this conversation:

EDIT:

actually I saw that in typescript we can create a event listener to any change using code like this (BUT works ONLY with SAME ts FILE):

Input.onKeyDown(() => { 
        Scene.setProperty(
            "R", 
            `${Math.random()}`
        ) 
    }, 
    "space"
)

Scene.onPropertyChanged("R", (key) => {
    Debug.log(`👀 ${key}`)
})


EDIT 2:

  • :x: normal variables can’t be shared even with files typescript only (yeah you get intellisense, but in reality it will output null or undefined if you try to do so)
  • :white_check_mark: I found out also that 2 typescript files can read each other properties, so this is a good way to save state of app between multiple files.

question we still need to solve?

how to share state between typescript and codeblock? especially typescript --> codeblock

1 Like

Hai, i’m the author of the post you referred to in your first post.
First of all great research in figuring out what works and doesn’t work!
Sadly the typescript to codeblock communication still doesn’t seem to be fixed.

I did find a temporary workaround tho, which is quite dirty and only works in some cases.
I call it “Physical variables”

Basically you create a trigger or collision event listener in either coblocks or typescript depending on which script you want to know when something has changed.

Then when your variable changes lets say something turned from false to true, you could create a collision with two objects that the other script is listening for. This acts like a physical boolean in this case but you could extend it to communicate more complicated data by adding more collisions or get the name from the particular collided object.

But i didn’t experiment with it that much because in my case a simple physical boolean was enough.

I hope this helps.

Goodluck

1 Like