generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Calling from a global array

Previous Thread :: Next Thread 
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
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
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
02 Apr 2017 04:39 PM
print(game.Workspace["Name Of Script"].db[0])
Report Abuse
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
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 is not online. 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
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
02 Apr 2017 04:54 PM
so just print(_G.db[1])
?

Cos that throws up errors
Report Abuse
cntkillme is not online. 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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
02 Apr 2017 04:56 PM
Or they're running on different peers


Report Abuse
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
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
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
02 Apr 2017 05:06 PM
b
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
02 Apr 2017 05:07 PM
Why are you bumping? You have been given two possibilities of why it isn't working.


Report Abuse
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
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
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
02 Apr 2017 05:18 PM
Server global library ~= client global library ~= other client's global library ~= output global library


Report Abuse
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
02 Apr 2017 05:20 PM
I'm sorry I don't really understand
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
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
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
02 Apr 2017 05:22 PM
###
Report Abuse
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
02 Apr 2017 05:31 PM
Is there a way then to make it accessible?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
02 Apr 2017 05:32 PM
Don't define it in the command ####
Report Abuse
iSentinels is not online. iSentinels
Joined: 03 Jan 2009
Total Posts: 28706
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image