global variables? Topic is solved

A forum dedicated to George scripting questions
Post Reply
User avatar
Lukas
Posts: 526
Joined: 14 Jan 2011, 11:15
Contact:

global variables?

Post by Lukas »

Is there a way to save something to a global variable?

For example, can I create a button with 2 actions:

action1:

Code: Select all

GLOBAL myglobalvar = 4
action2:

Code: Select all

name[1] = "HELLO"
name[2] = "EVERYONE"
name[3] = "AU"
name[4] = "REVOIR"

PRINT(name[myglobalvar])
To make the button print "REVOIR"?

If not, is there any other way to achieve something like this?

Also, is there a cleaner way to create arrays/tables or even structs in George? Or the name array above the only way?
  • Lukas Sketch Panel
  • TVPaint Pro 11.7.3
  • MacBook Pro 2018 macOS Ventura 13.4.1 + PC Windows 10
  • Wacom Cintiq 27QHD + Wacom Intuos4
  • YouTube.com/@ClubBaboo
  • YouTube.com/@FrameOrder
User avatar
Thierry
Site Admin
Posts: 2780
Joined: 07 Jan 2013, 08:28

Re: global variables?

Post by Thierry »

Hi Lukas,

Took me a bit to understand, but George doesn't have software-global variables.
Variables in George are "restricted" to their own script and can't interact with instructions from another script.

However, I found a workaround for this, as I needed it years ago :p

You can use the command tv_WriteUserString to save a variable to your User Config, then use the command tv_ReadUserString to retrieve it.

In your case, the script could be written like this:

Action 1:

Code: Select all

section = "globalGeorge"
name = "globalVariable"
tv_WriteUserString section name 4
Action 2:

Code: Select all

name[1] = "HELLO"
name[2] = "EVERYONE"
name[3] = "AU"
name[4] = "REVOIR"

section = "globalGeorge"
name = "globalVariable"
default = "not found"
tv_ReadUserString section name
val = result

PRINT(name[val])
And in theory it should work.
Also, is there a cleaner way to create arrays/tables or even structs in George?
Unfortunately, not possible.
User avatar
Lukas
Posts: 526
Joined: 14 Jan 2011, 11:15
Contact:

Re: global variables?

Post by Lukas »

Ah! :) I remember using tv_WriteUserString a long time ago, had to see the function to remember it. That should work for my problem. Thank you!
  • Lukas Sketch Panel
  • TVPaint Pro 11.7.3
  • MacBook Pro 2018 macOS Ventura 13.4.1 + PC Windows 10
  • Wacom Cintiq 27QHD + Wacom Intuos4
  • YouTube.com/@ClubBaboo
  • YouTube.com/@FrameOrder
Svengali
Posts: 1571
Joined: 28 Dec 2006, 10:08

Re: global variables?

Post by Svengali »

This is a thread that discusses tv_WriteUserString and tv_ReadUserString and also discusses a technique callsd "StringPacking" that you might find useful.


Also note the last entry in that thread shows a way to create a script for packing and unpacking values in an array, which might work for you.

sven
TVP Pro 11.0.10-64bit Win10 - 64GB ram -2TB HHD - 256GB SSD - Wacom Cintiq 16, driver 6.3.41-1
Android Tablet: rel. 11, Samsung Galaxy Note10.1 - 32GB with microSD 32GB
Android Tablet: rel. 11.5, Samsung Galaxy Tab S7plus - 128GB with microSD 64GB
User avatar
Lukas
Posts: 526
Joined: 14 Jan 2011, 11:15
Contact:

Re: global variables?

Post by Lukas »

Very interesting Svengali, I'll try and wrap my head around that code. My George is very rusty, its quirks are quite hard to read and understand if you haven't touched it in a while. Thanks for pointing me in that direction!
  • Lukas Sketch Panel
  • TVPaint Pro 11.7.3
  • MacBook Pro 2018 macOS Ventura 13.4.1 + PC Windows 10
  • Wacom Cintiq 27QHD + Wacom Intuos4
  • YouTube.com/@ClubBaboo
  • YouTube.com/@FrameOrder
User avatar
NathanOtano
Posts: 1208
Joined: 01 Apr 2014, 07:07
Location: Biarritz, France
Contact:

Re: global variables?

Post by NathanOtano »

You can also store variables "per project" which can come handy :) https://wiki.tvpaint.com/index.php/Tv_W ... jectString

Also, you can write/read text anywhere in the clip dialogue/notes textboxes, project infos, and you can write text files with george
Working on Windows 10
Creator of Disnosc, providing storyboard, animation and design for 2D realistic pictural animation: https://www.disnosc.fr/ - nathanotano@disnosc.fr
Highly interested in animation workflows, I'm open to scripting new TVP functions for individuals and studios.
User avatar
Lukas
Posts: 526
Joined: 14 Jan 2011, 11:15
Contact:

Re: global variables?

Post by Lukas »

NathanOtano wrote: 01 Apr 2024, 13:53 You can also store variables "per project" which can come handy :) https://wiki.tvpaint.com/index.php/Tv_W ... jectString

Also, you can write/read text anywhere in the clip dialogue/notes textboxes, project infos, and you can write text files with george
Ah, good to know. Thanks!
  • Lukas Sketch Panel
  • TVPaint Pro 11.7.3
  • MacBook Pro 2018 macOS Ventura 13.4.1 + PC Windows 10
  • Wacom Cintiq 27QHD + Wacom Intuos4
  • YouTube.com/@ClubBaboo
  • YouTube.com/@FrameOrder
Post Reply