|
| 02 Apr 2017 04:38 PM |
| I have a script called "database" with the array "_G.db = {"hello"}" How would I print this value in the output? Currently using: "print(game.Workspace["Big ############## but this doesn't work |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 04:39 PM |
| print(game.Workspace["Name Of Script"].db[0]) |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 04:47 PM |
"22:46:18.804 - db is not a valid member of Script"
is the error im getting |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Apr 2017 04:49 PM |
| Storing things in _G doesn't make it a "child" of scripts. Just do _G.db[0] |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 04:54 PM |
so just print(_G.db[1]) ?
Cos that throws up errors |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 02 Apr 2017 04:55 PM |
| It's probably because that script ran before the other one that sets _G.db to that. |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 04:56 PM |
Or they're running on different peers
|
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 04:56 PM |
I'm just running it in the command window;
error: print(_G.db[1]):1: attempt to index field 'db' (a nil value)
with my array being currently: _G.db = {1, "goodbye"} |
|
|
| Report Abuse |
|
|
| |
|
|
| 02 Apr 2017 05:07 PM |
Why are you bumping? You have been given two possibilities of why it isn't working.
|
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 05:12 PM |
Yeah cntkillme was right
I was forgetting to actually run the script in command before so it was never actually setting up what the variable outputted
Didn't get what you meant at first since I presumed running it in the output should work - but wasn't running any scripts
Cheers lads |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 05:16 PM |
Wait.
If I set up the array in the output and then call it again in the output it is fine, but otherwise I'm getting the same error again.
Does this mean it's not being set up properly or is it to do with peers? |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 05:18 PM |
Server global library ~= client global library ~= other client's global library ~= output global library
|
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 05:20 PM |
| I'm sorry I don't really understand |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 05:22 PM |
| Defining a shared variable (`_G` or `shared`) in the command ### won't necessarily make it visible inside Scripts (necessarily because you might define it yourself). If you define a shared variable inside a Script, other Scripts will see it, but not LocalScripts. Again, if you define a shared variable on a client, all of a clients' scripts will be able to access the variable because the LocalScripts are running on their computer, but other clients won't be able to see the same shared variables. |
|
|
| Report Abuse |
|
|
| |
|
|
| 02 Apr 2017 05:31 PM |
| Is there a way then to make it accessible? |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 05:32 PM |
| Don't define it in the command #### |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2017 05:37 PM |
fixed it by adding a wait to ensure that it runs after the array has been loaded guess its not the best way and it would be better to do a while loop to check if its there I guess but for now it works |
|
|
| Report Abuse |
|
|