Quantcast
Channel: Questions in topic: "get"
Viewing all articles
Browse latest Browse all 215

Help with static variables not being saved

$
0
0
I made a script where all my scripts are written, I access them periodically so I don't have to write the same script over and over. Now I have a problem when I set a variable and read it again its ok, but when I set it and then go back to read it, its not set. I like to have a place where I can keep all my scripts that I need to access again and again from different scripts. using UnityEngine; using System.Collections; public class MyScript : MonoBehaviour { public static void setupGridList (int type, int g, int s, int p, int m, int b, int a, int grid) { int [,,,, ] planetLocation = new int [10,10,10 ,27,7]; int [,,,,,] satelliteLocation = new int [10,10,10,10,27,7]; if (type == 0) { // 0 = New Game / Restart // Resets Planets Grid List to 0 for (g = 0; g <=9; g++){ // Galaxy (g) for (s = 0; s <=9; s++){ // Star (s) for (p = 0; p <=9; p++){ // Planet (p) for (b = 0; b <=26; b++){ // GridBox (b) for (a = 0; a <=6; a++){ // Area (a) planetLocation[g,s,p,b,a] = 0; }}}}} // Resets Satellites Grid List to 0 for (g = 0; g <=9; g++){ // Galaxy (g) for (s = 0; s <=9; s++){ // Star (s) for (p = 0; p <=9; p++){ // Planet (p) for (m = 0; m <=9; m++){ // Satellite (m) for (b = 0; b <=26; b++){ // GridBox (b) for (a = 0; a <=6; a++){ // Area (a) satelliteLocation[g,s,p,m,b,a] = 0; }}}}}} print("New Grid"); } if (type == 1) { // 1 = Write to Grid satelliteLocation[g,s,p,m,b,a] = grid; print("Wrote #" + satelliteLocation[g,s,p,m,b,a]); } if (type == 2) { // 1 = Read Grid print ("Read #" + satelliteLocation[g,s,p,m,b,a]); }}} using UnityEngine; using System.Collections; public class Setup : MonoBehaviour { void Start () { MyScript.setupGridList(0,0,0,0,0,0,0,0); // 0 = Format Grid (New) MyScript.setupGridList(1,1,4,3,1,1,1,5); // 1 = Write to Grid Location MyScript.setupGridList(2,1,4,3,1,1,1,0); // 2 = Read from Grid Location } When I print in console my results are; New Grid Wrote #5 Read #0 So Read #0 should be 5, I went from Formatting, to Writing 5 at that location and it should read and stay 5 not revert back to 0 at that location. Am I doing something wrong? The script MyScript is not attached to anything, it is just there to hold all my scripts to access.

Viewing all articles
Browse latest Browse all 215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>