0

I was wondering if it was possible to reference a specific part of an array in a jagged array, sorry if that sounds confusing, let me explain.

I have a jagged array string variable here:

public string[][] allConvos;

Which is later assigned 10 string arrays as shown here:

    allConvos [0] = convo1;
    allConvos [1] = convo2;
    allConvos [2] = convo3;
    allConvos [3] = convo4;
    allConvos [4] = convo5;
    allConvos [5] = convo6;
    allConvos [6] = convo7;
    allConvos [7] = convo8;
    allConvos [8] = convo9;
    allConvos [9] = convo10;

And then it's supposed to be referenced by another script here:

convoText = script.allConvos[0][0];

But no matter what I've done, I get an error and convotext doesn't have anything assign to it. Could anyone tell me if it's possible to reference an array like this and if so what I'm doing wrong? Sorry if this has bee answered already, I couldn't find anything on stackoverflow and decided to see if I'd have better luck asking it myself.

Brian Rasmussen
  • 109,816
  • 33
  • 208
  • 305
  • 3
    The issue is not with code that you've posted. For example, we need to see the definitions of `convo1`, `convo2`, etc. to be able to help you. – Jashaszun Jul 24 '15 at 20:00
  • 1
    That is exactly how you would access an item in the array. What is the error message that you get? – Guffa Jul 24 '15 at 20:02
  • if your jagged array has two requirements [][] you cannot assign one []. E.g. allConvos[n][n] = blah... – FirebladeDan Jul 24 '15 at 20:05
  • @FirebladeDan huh? Not sure what you mean... `string[][] allConvos = new string[10][]; allConvos[3]=new string[4];` is perfectly valid... – Alexei Levenkov Jul 24 '15 at 20:13
  • Based on sample code you've provided your problem is covered in "Arrays" section of accepted answer to linked duplicate "What is NRE". If you are getting some other error - make sure to provide small complete sample and exact error message inline in the post so it can be re-opened. – Alexei Levenkov Jul 24 '15 at 20:15
  • @Everyone, ah I'm so sorry for wasting time, I should of searched for the error first instead of just jagged arrays, and I'll make sure before I submit another question, thank you for the reference. – LevelForge Jul 25 '15 at 03:07

0 Answers0