C
C#2y ago
alaa2008

✅ `unexpected symbol switch` error

hello everyone. i hope you all are doing great. i got a problem here. i am getting this error in unity:
91 Replies
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
Pastebin
using System;using SBS.Math;using SBS.Racing;using UnityEngine;[Add...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
alaa2008
alaa2008OP2y ago
its line 132 can someone please help me? thats the last error i need to fix for the project
cap5lut
cap5lut2y ago
afaik unity onlky supports up to c# 7.3, switch expressions were introduced in c# 8
alaa2008
alaa2008OP2y ago
oh i see. so how am i able to fix that switch error?
cap5lut
cap5lut2y ago
aaah, nvm, scratch that, u just have to edit the project file and raise the language version to at least 8
cap5lut
cap5lut2y ago
basically that
alaa2008
alaa2008OP2y ago
do i just have to type: <LangVersion>7.3</LangVersion>?
cap5lut
cap5lut2y ago
well, its needs to be at least 8.0 as mentioned already but yeah thats it
alaa2008
alaa2008OP2y ago
ok thx bro
cap5lut
cap5lut2y ago
9.0 seems to work as well (just checked one of my projects and since its autogenerated by unity i guess they support it, at least in version 2022)
alaa2008
alaa2008OP2y ago
uh just a quick question: where exactly do i have to add the <LangVersion>7.3</LangVersion> ? i mean which line? if you know what i mean
ero
ero2y ago
doesn't matter, as long as it's in a <PropertyGroup> which itself is in a <Project>
alaa2008
alaa2008OP2y ago
oh i see thx
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
so i have it here do i have to change the version to 8.0?
cap5lut
cap5lut2y ago
u have already 11 in there, that means switch expression should actually work and the issue lies somewhere else but then i have no clue either
alaa2008
alaa2008OP2y ago
hmm ok thx
cap5lut
cap5lut2y ago
which vs version r u using?
alaa2008
alaa2008OP2y ago
2022
cap5lut
cap5lut2y ago
hmm
alaa2008
alaa2008OP2y ago
i never figured it out i think this will be a challenge its just so hard to fix this does anyone has an idea how to fix that?
ero
ero2y ago
don't use switch expressions?
alaa2008
alaa2008OP2y ago
yea but then i will get more errors
ero
ero2y ago
what? that doesn't make sense
alaa2008
alaa2008OP2y ago
here removed the switch thing
alaa2008
alaa2008OP2y ago
ero
ero2y ago
that's not how that works, no you need to convert the switch expression to some other way of returning the correct values
public static float GetTrasversalFromLane(int roadLane)
{
switch (roadLane)
{
case 0: return -0.75f;
case 1: return -0.25f;
case 2: return 0.25f;
case 3: return 0.75f;
default: return 0f;
}
}
public static float GetTrasversalFromLane(int roadLane)
{
switch (roadLane)
{
case 0: return -0.75f;
case 1: return -0.25f;
case 2: return 0.25f;
case 3: return 0.75f;
default: return 0f;
}
}
alaa2008
alaa2008OP2y ago
oh i got it fixed thank you so much bro @just_ero ayo bro how about here?
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
same error wait let me send full code
alaa2008
alaa2008OP2y ago
Pastebin
using System;using System.Collections.Generic;using SBS.Core;using ...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
alaa2008
alaa2008OP2y ago
line 50
cap5lut
cap5lut2y ago
then ... use the same way to fix it and use a switch statement instead of a switch expression?
ero
ero2y ago
same way to fix it
alaa2008
alaa2008OP2y ago
oh right thx guys does anyone know what wrong here is?
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
i already tried int hitInfo; i still get errors when i do that like this
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
Pastebin
using System.Collections.Generic;using SBS.Core;using SBS.Math;usin...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
alaa2008
alaa2008OP2y ago
line 96
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
i tried everything i could nothing worked
cap5lut
cap5lut2y ago
did u change the csproj file?
alaa2008
alaa2008OP2y ago
no
cap5lut
cap5lut2y ago
then something is wrong with ur IDE as it thinks the project is in c# 6, not in c# 11 (thats probably also the reason why the switch expressions earlier didnt work)
alaa2008
alaa2008OP2y ago
is it fixable? i mean the error
cap5lut
cap5lut2y ago
i have no clue whats causing it so i dunno
alaa2008
alaa2008OP2y ago
ok thx
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
alaa2008
alaa2008OP2y ago
Couldn't fix it It is too hard But we are getting closer The token thing is finished Now there is another error Here it is the TrackBranch I will send the link of the full code later Since now i am not home Yea it's here
alaa2008
alaa2008OP2y ago
Pastebin
using System.Collections.Generic;using SBS.Core;using SBS.Math;usin...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
alaa2008
alaa2008OP2y ago
Line 98 hitInfo.token.TrackBranch guys guys i was stupid i opened the wrong .cs file with the langversion @cap5lut
MODiX
MODiX2y ago
Sorry @alaa2003 your message contained blocked content and has been removed!
alaa2008
alaa2008OP2y ago
i was ret arded i opened the wrong project file this is the real one
alaa2008
alaa2008OP2y ago
cap5lut
cap5lut2y ago
well, then change the lang version
alaa2008
alaa2008OP2y ago
to which version 11? or 8
cap5lut
cap5lut2y ago
9 is max it seems currently for unity
alaa2008
alaa2008OP2y ago
ok so like i said before i fixed the token thing
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
now there are 2 errors left for the TrackBranch its: 'object' does not contain a definition for 'TrackBranch' and no accessible extension method 'TrackBranch' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?). any idea how to fix this error?
cap5lut
cap5lut2y ago
maybe TrackBranch trackBranch = (TrackBranch)hitInfo.token.TrackBranch;, but thats just guessing
alaa2008
alaa2008OP2y ago
Ok thx bro
cap5lut
cap5lut2y ago
note, that if hitInfo.token.TrackBranch is not a TrackBranch it will throw a cast exception at runtime
alaa2008
alaa2008OP2y ago
It is (Maybe)
cap5lut
cap5lut2y ago
most probably
alaa2008
alaa2008OP2y ago
Okay bro I will try it out later Thx again man nope still got the error uh a question how do i have to fix the switch thing here? Yea give me a sec My internet is fucked A bit here
alaa2008
alaa2008OP2y ago
cap5lut
cap5lut2y ago
like the other times, just instead of returning u set the variable (_ is the default branch)
alaa2008
alaa2008OP2y ago
ok thx bro so would it be switch (m_CarSettings.tractionAxle) ?
cap5lut
cap5lut2y ago
yep
alaa2008
alaa2008OP2y ago
I tried it out yesterday I got too many errors
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
whats this? the get_length never got that error before what to do here? 'Extensions.length.get' : cannot explicitly call operator or accessor
cap5lut
cap5lut2y ago
did u decompile some dll and try to make the resulting code working for ur game?
alaa2008
alaa2008OP2y ago
oh its just a game called Motorway-Mayhem it was an old police game from my childhood, but since the UnityPlayer got removed from browsers, i tried to make a standalone version of the game since some people asked me i decompiled them with ilSpy or i just don't understand your question xd
cap5lut
cap5lut2y ago
nah, u did answer my question
alaa2008
alaa2008OP2y ago
oh i see
cap5lut
cap5lut2y ago
but i doubt u r allowed to do this, so its against this servers rules and against discord's ToS, so i stop providing help here
alaa2008
alaa2008OP2y ago
oh ok just a quick question. why is it not allowed to decompile .dll files?
cap5lut
cap5lut2y ago
In the U.S., for example, copyright laws don't fully restrict decompilation. The Digital Millennium Copyright Act (DMCA) allows reverse-engineering, if a person has lawfully obtained a right to use a copy of a computer program, only to identify and analyze its elements to achieve interoperability with other programs. However, decompiling a program to circumvent a system that controls access to copyrighted work is considered illegal. Similarly, the EU also allows decompilation for some uses, including interoperability.
u dont only want to interop, but u want to break copyrights and share it
alaa2008
alaa2008OP2y ago
oh i see so i live in germany is it still not allowed? in EU.
cap5lut
cap5lut2y ago
yep, its not allowed here either (im from germany as well)
alaa2008
alaa2008OP2y ago
oh i see hmm thats sad ok then thx again also you won't help me even if i don't upload the game to public? because i am the only one who will play it my friends also know the game and who the developer is i will send it to them and i will also credit the original creator they will keep it private but that doesn't change anything right?
cap5lut
cap5lut2y ago
yeah, that doesnt change anything if u sit in the cinema recording what ya watch and give it ur friends and say "hey thats from pixar, dont give it to others" thats still piracy
alaa2008
alaa2008OP2y ago
yea ok then got it
cap5lut
cap5lut2y ago
well, as we cant help u further can u please $close this thread?
MODiX
MODiX2y ago
Use the /close command to mark a forum thread as answered
alaa2008
alaa2008OP2y ago
yea
Want results from more Discord servers?
Add your server