C
C#10mo 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
Angius10mo ago
What are those errors?
Spartan
SpartanOP10mo ago
CS1001 "identifier expected" CS1002 just says "expected" ?
Angius
Angius10mo 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
SpartanOP10mo ago
yes
Angius
Angius10mo ago
$vscode
MODiX
MODiX10mo 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
Angius10mo ago
Make sure you have DevKit installed
Angius
Angius10mo ago
In any case, this
No description
Angius
Angius10mo 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
SpartanOP10mo ago
when i take the "this." out it tells me i cant use local variable before it is declared.
Angius
Angius10mo 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
SpartanOP10mo ago
im trying to get the token to randomly generate between the numbers of 0 and 7
Angius
Angius10mo ago
I don't know what token is Is this Unity?
Spartan
SpartanOP10mo 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
Angius10mo ago
Sooooo... TokenToUse is an existing property or field of the class, yes?
Spartan
SpartanOP10mo ago
yes
Angius
Angius10mo ago
Remove the int then
Spartan
SpartanOP10mo ago
it now gives me these lovely things
No description
Spartan
SpartanOP10mo ago
maybe i start over?
Angius
Angius10mo ago
Are you sure the property is actually there? Not in some other file? Some other class?
Spartan
SpartanOP10mo ago
i think i may have missed it, its not in another script, its only mentioned here.
Angius
Angius10mo ago
If that was the case, the first error would not be there
Spartan
SpartanOP10mo ago
could it be because i wrote the other script in visual studio 22? or would that not matter?
Angius
Angius10mo ago
It wouldn't matter Can you send the whole file here? Well, the $code of the whole file?
MODiX
MODiX10mo 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
SpartanOP10mo ago
want me to just paste the code or screenshot it?
Vi Ness
Vi Ness10mo 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
SpartanOP10mo 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
SpartanOP10mo 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
Angius10mo ago
Glad you got it sorted!
Spartan
SpartanOP10mo ago
should i leave this post up incase others come across similar issues or shall i close it?
Angius
Angius10mo ago
If you $close it it will stay up
MODiX
MODiX10mo ago
Use the /close command to mark a forum thread as answered
Angius
Angius10mo ago
Just gonna get a green checkmark next to the title
Want results from more Discord servers?
Add your server