#list

1 messages · Page 1 of 1 (latest)

narrow atlas
#

so

tidal wave
#

Hey

narrow atlas
#

what about printing shelfdatalist?

tidal wave
#

I already did that

#

Always come out as 0

#

been stuck with this issue for 2 days

narrow atlas
tidal wave
#

ive had a couple guys try to help, but no luck unfortunatly

tidal wave
#

huh?

narrow atlas
tidal wave
#

moso from the other server?

#

you changed you rname

narrow atlas
#

nickname

#

servers have those

tidal wave
#

ohh

#

ok

pearl shadow
#

Did you log the three variables Digi said could be null? 🤔

#

Log and check their value before the error line . . .

tidal wave
#

they arnt variables

#

the only variable is the list

#

and thats whats returning null

#

but no idea why

pearl shadow
#

Then you know the issue; it's null. Assign it a value . . .

#

You're tryna access the list but it's null, it has not been initialized or assigned a value . . .

tidal wave
#

if thats the case, i dont know how to do that

#

it should work

pearl shadow
#

You gotta know how to initialize a list. If not, Google how to . . .

tidal wave
#

even if the list is 0, the line is to add onto the list

#

Yeah I know how google works, I wouldent be here if i hadnt already tried

pearl shadow
#

It's not zero, it doesn't exist yet . . .

tidal wave
#

it is 0

#

because I logged it

narrow atlas
#

shelfdatalist = new ShalfData();

tidal wave
#

the dataList is in the Json script, this would just return an error

pearl shadow
#

You don't need a parameter. They could've easily Googled that though . . .

narrow atlas
#

?

#

aka initialized

#

don't confuse with declare

tidal wave
#
 public List<ShelfData> shelfDataList = new List<ShelfData>();```
#

You mean this?

tidal wave
#

Yeah of course I have this

narrow atlas
tidal wave
#

didnt think of this, so worth a shot to try

#

The list is not null

#

it seems to be the script that is null (ShelfData) or something within it

narrow atlas
#
var e = new ShelfData();
SaveLoad.gameData.shelfDataList.Add(e);```
tidal wave
#

still null reference

narrow atlas
tidal wave
#

Line 14

#

of ShelfData

narrow atlas
#

say the var
or the save

tidal wave
#
        position = new float[3] { tableScript.transform.position.x, tableScript.transform.position.y, tableScript.transform.position.z };```
#

Which is weird because why would this line return null

#

makes no sense

narrow atlas
pearl shadow
#

Hmmm, you said shelfData wasn't null . . .

tidal wave
#

I said the list wasnt null

narrow atlas
pearl shadow
#

At this point, log every reference variable you try to access before the error to get a clear picture of what is null . . .

tidal wave
#

Yeah im trying

#

I cant log anything in Shelf Data

#

im not sure how to access it

narrow atlas
#

i will modify it

tidal wave
#
[System.Serializable]
public class ShelfData
{
    public float[] position;
    public float[] rotation;
    public int appleCount;
    private ShelfData shelfData;

    public Shelf tableScript;

   

    // To be called to serialize the table script into json
    public ShelfData() 
    {
        position = new float[3] { tableScript.transform.position.x, tableScript.transform.position.y, tableScript.transform.position.z };
        rotation = new float[3] { tableScript.transform.eulerAngles.x, tableScript.transform.eulerAngles.y, tableScript.transform.eulerAngles.z };
        appleCount = tableScript.applesAdded;
    }


    // To be called when deserializing the table from json
    public void ApplyTo() {
        tableScript.transform.position = new UnityEngine.Vector3(position[0], position[1], position[2]);
        tableScript.transform.eulerAngles = new UnityEngine.Vector3(rotation[0], rotation[1], rotation[2]);
        tableScript.applesAdded = appleCount;
    }

   




}
narrow atlas
#

thanks

#
// To be called to serialize the table script into json
    public ShelfData() 
    {
Debug.Log(position);
Debug.Log(rotation);
Debug.Log(tableScript);
Debug.Log(appleCount);
        position = new float[3] { tableScript.transform.position.x, tableScript.transform.position.y, tableScript.transform.position.z };
        rotation = new float[3] { tableScript.transform.eulerAngles.x, tableScript.transform.eulerAngles.y, tableScript.transform.eulerAngles.z };
        appleCount = tableScript.applesAdded;
Debug.Log(position);
Debug.Log(rotation);
Debug.Log(tableScript);
Debug.Log(appleCount);
    }
tidal wave
#

I dont think i can do this

#

because its a serialised class

narrow atlas
tidal wave
#

?

narrow atlas
tidal wave
#

i cant log anything because its a serialised class tho

narrow atlas
#

btw tablescript is null by default

tidal wave
#

Its ok, im going to wipe eveyrthing and start from scratch

narrow atlas
#

cause the class was just made

#

so if you were to make a new vector3

#

every value will be 0

#

but here you have a class reference and not a float

#

so its default value will be null

#

@tidal wave

tidal wave
#

so how should i set it ?

#
    public Shelf tableScript = new Shelf();```?
#

ok thats weird

narrow atlas
tidal wave
#

so im still getting an error

#

but its different

#

just a null reference exception

narrow atlas
#

let me guess

tidal wave
#

hmm

narrow atlas
#

use a null check

#

or

tidal wave
#

wait, or maybe the transform is null,

#

i need to figure out how to change the transfor before adding to list

narrow atlas
#

from the new Shelf();

#

so

#

do this

#
// To be called to serialize the table script into json
    public ShelfData() 
    {
if(tableScript != null) {
        position = new float[3] { tableScript.transform.position.x, tableScript.transform.position.y, tableScript.transform.position.z };
        rotation = new float[3] { tableScript.transform.eulerAngles.x, tableScript.transform.eulerAngles.y, tableScript.transform.eulerAngles.z };
        appleCount = tableScript.applesAdded;
}
    }
#

@tidal wave then by having tablescript public

#

wait nvm

#

could just use a parameter called newtablescript

#

or make this method different and not be called with new

#

you choose

#

@tidal wave

narrow atlas
# narrow atlas or make this method different and not be called with new
[System.Serializable]
public class ShelfData
{
    public float[] position;
    public float[] rotation;
    public int appleCount;
    private ShelfData shelfData;

    public Shelf tableScript;
   
    // To be called to serialize the table script into json
    public void SetData() 
    {
        position = new float[3] { tableScript.transform.position.x, tableScript.transform.position.y, tableScript.transform.position.z };
        rotation = new float[3] { tableScript.transform.eulerAngles.x, tableScript.transform.eulerAngles.y, tableScript.transform.eulerAngles.z };
        appleCount = tableScript.applesAdded;
    }

    // To be called when deserializing the table from json
    public void ApplyTo() {
        tableScript.transform.position = new UnityEngine.Vector3(position[0], position[1], position[2]);
        tableScript.transform.eulerAngles = new UnityEngine.Vector3(rotation[0], rotation[1], rotation[2]);
        tableScript.applesAdded = appleCount;
    }
}```
tidal wave
#

yh im trying to see if I can change the transform from another script before I call add but cant seem to access it

narrow atlas
# narrow atlas could just use a parameter called newtablescript
[System.Serializable]
public class ShelfData
{
    public float[] position;
    public float[] rotation;
    public int appleCount;
    private ShelfData shelfData;

    public Shelf tableScript;

   

    // To be called to serialize the table script into json
    public ShelfData(newTable) 
    {
tableScript = newTable;
        position = new float[3] { tableScript.transform.position.x, tableScript.transform.position.y, tableScript.transform.position.z };
        rotation = new float[3] { tableScript.transform.eulerAngles.x, tableScript.transform.eulerAngles.y, tableScript.transform.eulerAngles.z };
        appleCount = tableScript.applesAdded;
    }


    // To be called when deserializing the table from json
    public void ApplyTo() {
        tableScript.transform.position = new UnityEngine.Vector3(position[0], position[1], position[2]);
        tableScript.transform.eulerAngles = new UnityEngine.Vector3(rotation[0], rotation[1], rotation[2]);
        tableScript.applesAdded = appleCount;
    }

//example of use
var e = new ShelfData(Example);

}```
narrow atlas
narrow atlas
#

do
var e = new ShlefData();

e.tableScript = anything;
e.SetData();

#

@tidal wave

tidal wave
#

yeah im trying to figure it out but i really dont know, im so tired

#

I think im just going to delete it all and restart

narrow atlas
#

focus on other things

tidal wave
#

Yeah, but cant focus on other things as this mechanic ive been trying to add is the most important

#

oh well im done, C# wins

narrow atlas
#

what about making the main menu?

#

or ui?

tidal wave
#

appreciate you taking so much time to help

narrow atlas
tidal wave
#

Yeah true, but i guess im one of those people that just cant leave something unfinished

#

severe OCD

#

haha im glad you had fun

pearl shadow
tidal wave
#

ive re-written everything

#
[System.Serializable]
public class ShelfData
{
    public float[] position;
    public float[] rotation;
    public int appleCount;
  

   
    // To be called to serialize the table script into json
    public ShelfData(Shelf tableScript) 
    {
        position = new float[3] { tableScript.transform.position.x, tableScript.transform.position.y, tableScript.transform.position.z };
        rotation = new float[3] { tableScript.transform.eulerAngles.x, tableScript.transform.eulerAngles.y, tableScript.transform.eulerAngles.z };
        appleCount = tableScript.applesAdded;
    }


    // To be called when deserializing the table from json
    public void ApplyTo(Shelf tableScript) {
        tableScript.transform.position = new UnityEngine.Vector3(position[0], position[1], position[2]);
        tableScript.transform.eulerAngles = new UnityEngine.Vector3(rotation[0], rotation[1], rotation[2]);
        tableScript.applesAdded = appleCount;
    }

   




}
#

The only thing I cant get working is this

#
   SaveLoad.gameData.shelfDataList = SaveLoad.gameData.shelfDataList.ConvertAll(tableScript => new ShelfData(ShelfData));```
pearl shadow
#

Is the list initialized or populated? Are you re-assigning it to itself . . .