I’ll try to explain the problem I’m having, a little better… I have script_A attached to a cloned game-object… the script_A works just fine… when I try to reference script_A from script_B… I get a null reference error… I don’t get errors referencing other scripts… just this one… My guess is because it is on a clone… so the script is multiplied (cloned) on each copy of the game-object (clones)… and that is exactly what I want… each clone runs script_A and they all collect their variables separately for each … but then how do I reference script_A… when it is really multiple-script_A’s… ???.. I hope someone can understand my question… sorry I can’t explain it any better because I am very new to programming… any help would be great… thanks
Debugging code requires readable code
I’d start by saying that this is really difficult to read. Not because it’s hard code, but because the naming conventions are incomprehendable.
I litterally have to use the Highlight All feature in my webbrowser to find the same variables. Not very smart. Good code is readable code.
I’d love to dig into your code, but the naming convention really would make it more of a hazzle than in needs to be.
I honestly have no idea what this code does. Here’s a guess of what you’re trying to tell me through your naming conventions (which might be off).
[Header("P1 / Number Of Total Tile Moved / To date")]
public int startTile; // Dic_INT_Value
public int currentTile = 0; // TEMP_CurrentTileNumberTotal_P1
public int nextTile; // IntValueSumOf_UpdatedCurrentDiceTotalPlus_ThisCloneP1
public List<int> moves = new List<int>(); // TEMP_PlayerStone1_MoveNumCount_List
public Dictionary<PlayerStone, int> playerStoneTile = new Dictionary<PlayerStone, int>(); // TEMP_PlayerStone1_MoveNumCount_Dictionary
public PlayerStone playerStone; // THIS_PlayerStone
public int sumOf_DiceTotalPlus_ThisCloneP1; // ???
void Start()
{
// Add current tiles to moves
moves.Add(currentTile);
playerStoneTile.Add(playerStone, currentTile);
Debug.Log("PlayerStone Moves: " + playerStoneTile.Count);
// Get PlayerStone tile
startTile = currentTile;
}
void Update()
{
if (Static_Class_Variables.CurrentPlayerId == 0)
{
nextTile = ((startTile) + Static_Class_Variables.Global_DiceTotal_Copy);
}
}
Hi what I believe you are trying to say is that you are having trouble referencing another variable from another script.
Your code is very hard to read and understand, I would suggest learning how to use camel casing and use general naming conventions IE: Shorten TEMP_PlayerStone1_MoveNumCount_List to just playerStone1_Move
to reference another a variable from another script you must get the script in your Start method
testScript testScriptReference = testScriptReference.GetComponent();
Then from here you can reference by using
testScriptReference.testVariable
Thanks for trying to help… I know this does not conform to standard C# conventions… but I have been coding for about 3 months… I’m learning as I go… My strength is in graphics… It’s not that I don’t want to learn all the proper coding conventions… but that is secondary to getting things done right now… I really shouldn’t have posted any of the code… my question has more to do with referencing the script … this script is attached to a clone… I can’t seem to reference it, in the same way, I reference other scripts… this script is not the problem… it’s referencing this script from another script that is the problem… Thanks anyways… I’m going to cut the code out of my question