python access to global or private variables

This forum is currently in read-only mode.
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I can't seem to get Python code to to read either global or private variables... it feels like I'm doing something wrong so maybe someone here like Lucid or Davo knows. Anybodies help if of course appreciated!

    For example if mytext1,2,and 3 are python variables and inputtext is a Contruct global:

    mytext = text

    mytext2 = global('text')

    mytext3 = str(Array.CurrentValue)

    The first two attempts give an error. Only by sticking the inputtext in an Array could I then assign it to a Python variable.

    Here is an example .cap: http://www.box.net/shared/giskjujjgl

    How are people interfacing global and other variables in with Python?

  • Python access to global or private variables is currently broken, but here's a few related fixes that hopefully can be put into the next release: http://www.scirra.com/forum/viewtopic.php?f=7&t=5921.

    In the mean time you can use a hybrid method like this:http://www.box.net/shared/981crp7jvh

  • You just made my week! I had pretty much given up on this so it is absolutely fantastic that you found a workaround and fixed the bugs. Awesome work!

  • Now it seems like I am having problems in the opposite direction. I can't set a global variable from Python script.

    For example:

    A global called startGame.

    In script:

    globalvar('startGame') = 1

    global('startGame') = 1 <--- i know shouldn't work based on the fixes

    globalvar("startGame") = 1

    I seem to have tried every combination I can think of and I get an error "can't assign to function call" I've tried casting to string, to int.. all sorts of combinations. Just doesn't work.

    Any ideas?

  • Same as with actions in the event sheet:

    System.SetGlobalVar("startGame", value)

    System.globalvar("startGame") only retrieves the value of the global variable, aka you cannot modify the global with an assignment operator.

  • Thanks! Makes perfect sense now.

  • Now, I can't seem to get private variable access in Python to work. I'm using the latest .99.84

    I have a sprite called "player" and a private variable called "score".

    I tried player.Value("score") which doesn't error but doesn't retrieve anything. I regular event retrieves the value fine so I know something is there. I also tried player.GetValue("score") which causes an error.

    Any ideas why this doesn't work?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • yeah in order to use private variables in python the plugins that use them need to be recompiled. Until then they don't work... I'll see if I can get the necessary plugins recompiled before the next build.

  • Could python access to global/private variables please be added to the wiki in the python part of it?

    Seems like many before me have had the same problems as me >_>

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)