Not randome range

so i am doing a short story game instead of q and a quiz master game,
and I needed a way to set a range in a not random way. I’m not sure if this will work later on in the game but this is what i came up with.

[Range(0, a)] int questionRange;
const int a = 0;

void Start()
{
int a = questions.Count;
}

This won’t work. a is defined as a constant and can’t be changed. You are setting a new, different a in Start() that will be lost again as soon as Start() is finished executing. Your range will always be from 0 to 0.

I’m not sure why you would want to set a Range. You just need to use the size of your ‘question’ list. You don’t need the Range bits at all.

1 Like

so that i can change the size of list along with range as it would with random.range.
i don’t know how if it gets set back to 0 after start but it dose seem to work i am getting all my questions in order as i want them to. after last question is complete i then get

ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

which i assumed is from the index being empty after all currentQuestions are removed

The [Range] attribute is used by the inspector to create a slider. If your questionRange was exposed in the inspector (which it isn’t from what I can see here) it would have a range from 0 to 0. This is because the constant a is always 0. You also don’t set the questionRange to anything, so that will default to 0. That is at least what I can see from the bits you’ve shared.

Yes, you probably get this ‘argument out of range’ exception because there are no more questions in the list and you are trying to access them

so i did play with is some more it dose not need start to function and i didn’t notice last night but my first question seems to be missing so dose that mean that it sets a range 0-0 which then removes the first question but then continues on out side of range?

I don’t know. I don’t know what your code does apart from what you’ve shared above. Also, the Range does not mean anything here. It is used purely by the inspector

i see the missing question did seem to have anything to do with range it was an if statement
that takes out fist question. any way thank you for your help i appreciate it .

Privacy & Terms