C
C#17mo ago
Tidan

❔ Cant Find Key Type Byte In Dictionary?

Dictionary contains variables which are given byte values. These values are not in order, they go from 2 3 4 5 -> 13 then jumps a few to 30 -> 40. Which is why I set it up in a dictionary. This dictionary is never modified given its a static. So I have no clue why it can't find "3" in the dictionary with should and is "ItemData.MaxMP"
27 Replies
Tidan
Tidan17mo ago
Some Screenshots:
Tidan
Tidan17mo ago
Tidan
Tidan17mo ago
Tidan
Tidan17mo ago
Tidan
Tidan17mo ago
If it would make it any easier I can go through a screen share session. To explain the process. 1: I look inside a dictionary and grab bytes that will translate to values higher than 0. 2: Store them inside a list of bytes. 3: Then roll a random byte out of that list (simulating rolling a random stat to enhance out of 4 stats) 4: Then call back to the same dictionary I used in step 1 to grab the value of that stat. Finally, set the value of that stat to be increased by a random %, up to 20% and append it on top of the value the stat already had. Everything works except that i'm getting this weird error... that of which I cant find a solution for. AGONY
Scratch
Scratch17mo ago
I don't know the answer, but I recommend setting a breakpoint and inspecting the contents of the dictionary in the debugger
Tidan
Tidan17mo ago
hmm so im noticing something weird or maybe Im thinking of dictionaries wrong... so when calling a value of a specified key, you use dictonaryName[key]? Correct? that returns the value by default?
Tidan
Tidan17mo ago
Wait im so much confusion...
Tidan
Tidan17mo ago
why is 4 5 6? where is 2??? what?
Tidan
Tidan17mo ago
where is it getting these values is my question
Tidan
Tidan17mo ago
hmmmmmm... count 18, i have 21 elements...
Scratch
Scratch17mo ago
that'll heavily depend on your code
Tidan
Tidan17mo ago
okay lemme look around, im doing something wrong, i thought it was the dictionary but its not. Hello I see the issue I think... To which I have a question
Tidan
Tidan17mo ago
Tidan
Tidan17mo ago
How can I copy over a dictonary to another variable without modifying the original dictionary? because I thought this would make a local clone of the dictonary in my function so I could check which stats could be rolled but instead, it modifies the original dictionary... which it kinda makes sense why it doesnt clone it it just points to the dictonary not makes a new one
Scratch
Scratch17mo ago
create a new dictionary and insert new keys/values into it
Tidan
Tidan17mo ago
just to turn this into a learning experience a dictionary is a object and is not a datatype.
Scratch
Scratch17mo ago
It's pass by reference vs pass by value
Tidan
Tidan17mo ago
so when u copy an object in a variable yeah okay and quick question is it possible to copy a array by just doing var array = otherarray and when u modify the array variable, only that array is modified. not the other
Scratch
Scratch17mo ago
Value types - C# reference
Value types vs reference types, kinds of value types, and the built-in value types in C#
Scratch
Scratch17mo ago
is it possible to copy a variable by just doing var array = otherarray
no, you need to create a new one somehow. For an array you can do var array = otherarray.ToArray();
Tidan
Tidan17mo ago
so you save the reference to an array when you assign it to a variable. to make a new array, you have to assign it to an array value? like not value but something that returns an array.
Scratch
Scratch17mo ago
if you wanted to do it yourself you could do:
var array = new Foo[otherarray.Length];
for (var i = 0; i < otherarray.Length; i++) {
array[i] = otherarray[i];
}
var array = new Foo[otherarray.Length];
for (var i = 0; i < otherarray.Length; i++) {
array[i] = otherarray[i];
}
that's what ".ToArray()" does I think there's an equivalent "ToDictionary()" too, but I'd need to check
Tidan
Tidan17mo ago
oh okay thanks for the help thats interesting, never really noticed this stuff but it makes sense
Scratch
Scratch17mo ago
looks like var clone = new Dictionary(otherdictionary);
Tidan
Tidan17mo ago
sounds good thanks a lot, any info on how to close these? oh wiat i found it
Accord
Accord17mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.