C
C#5mo ago
Spartan

✅ I dont know what im doing wrong?!

go easy as im very new, im essentially making a simple match 3 game to learn c#. ive managed to get my game board to generate, but i cant seem to figure out why im getting a CS1001 and CS1002 errors in this pictured area. origonally i was getting a CS0844 error but have since fixed that with a "this." but now i get the previous mentioned errors. im trying to figure it out on the microsoft learn but im still not overly sure what to change to make it work ?! some help would be greately appreciated!
No description
34 Replies
Angius
Angius5mo ago
What are those errors?
Spartan
Spartan5mo ago
CS1001 "identifier expected" CS1002 just says "expected" ?
Angius
Angius5mo ago
Well, I can see at least one issue here Curious why the IDE doesn't highlight it in red Is it VS Code?
Spartan
Spartan5mo ago
yes
Angius
Angius5mo ago
$vscode
MODiX
MODiX5mo ago
Follow the instructions here on getting started with DevKit for C# in VSCode: https://code.visualstudio.com/docs/csharp/get-started
Get started with C# and .NET in Visual Studio Code
Getting Started with C# and .NET Development in Visual Studio Code
Angius
Angius5mo ago
Make sure you have DevKit installed
Angius
Angius5mo ago
In any case, this
No description
Angius
Angius5mo ago
Are you creating a new variable? If so, the this should not be there Are you trying to change the value of an existing property/field? If so, then the int sholdn't be there
Spartan
Spartan5mo ago
when i take the "this." out it tells me i cant use local variable before it is declared.
Angius
Angius5mo ago
Again, what are you trying to do here? Change the value of existing variable? Then don't declare the type. Create a whole new variable? Then give it a new name, don't reference an existing field/property
Spartan
Spartan5mo ago
im trying to get the token to randomly generate between the numbers of 0 and 7
Angius
Angius5mo ago
I don't know what token is Is this Unity?
Spartan
Spartan5mo ago
sorry my apologies, basically at the start of this script, ive made "token" as part of an array, so the line of code you highlighted is for it to pick a number between 0 and 7 (as thats how many "tokens" there will be) and then generate them randomly within the board.
Angius
Angius5mo ago
Sooooo... TokenToUse is an existing property or field of the class, yes?
Spartan
Spartan5mo ago
yes
Angius
Angius5mo ago
Remove the int then
Spartan
Spartan5mo ago
it now gives me these lovely things
No description
Spartan
Spartan5mo ago
maybe i start over?
Angius
Angius5mo ago
Are you sure the property is actually there? Not in some other file? Some other class?
Spartan
Spartan5mo ago
i think i may have missed it, its not in another script, its only mentioned here.
Angius
Angius5mo ago
If that was the case, the first error would not be there
Spartan
Spartan5mo ago
could it be because i wrote the other script in visual studio 22? or would that not matter?
Angius
Angius5mo ago
It wouldn't matter Can you send the whole file here? Well, the $code of the whole file?
MODiX
MODiX5mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Spartan
Spartan5mo ago
want me to just paste the code or screenshot it?
Vi Ness
Vi Ness5mo ago
It's easier to read if you paste it in a code block the way that the bot described. And if it's a larger file, use the link and host it there
Spartan
Spartan5mo ago
I'll take another look later after work, thank you for the patience and input. omfg, ive figured it out it was a simple name confliction within the ( ) and the rest of the code, it now works, thank you for the help!
Spartan
Spartan5mo ago
for reference it was the names highlighted that needed to be different. i shouldnt be figuring out code at 1am lol thanks again though @ZZZZZZZZZZZZZZZZZZZZZZZZZ
No description
Angius
Angius5mo ago
Glad you got it sorted!
Spartan
Spartan5mo ago
should i leave this post up incase others come across similar issues or shall i close it?
Angius
Angius5mo ago
If you $close it it will stay up
MODiX
MODiX5mo ago
Use the /close command to mark a forum thread as answered
Angius
Angius5mo ago
Just gonna get a green checkmark next to the title