A little issue tryin' to personalize obstacle course -need help Y__Y

Hi!
First of all, sorry if this is a dumb question: I’m a totally noob in programming, please be patient XD

I’m triyng to add an incremental speed boost to my character when it touches specific tiles on the floor during the course (in order to rise the difficulty more and more).


this is my attempt, but it doesn’t work ( it says the name “turbo” does not exists in the current context, even if I declared the variable)… Where is the error!?

Hi YRO,

First of all, please do not apologise for asking questions. Asking questions is a crucial part of everybody’s learning process, and we all are learning here. Even Rick is still learning. Every good programmer is always learning new things because technology constantly evolves.

Secondly, it would be great if you could post your code as formatted text because screenshots are difficult to read, and we cannot copy and paste any lines from pictures.

Thirdly, where is the turbo variable declared? According to your screenshot, there is a local turbo variable declared und the MovePlayer method. The OnCollisionEnter method cannot access that variable because that variable does not exist within the same scope of the OnCollisionEnter method. Since I cannot see the rest of your code, I don’t know if you also have an instance variable named turbo, which can be found at the top of your class.

Apart from the issue with the scope, your code looks fine and should, theoretically, work once you put the turbo variable at the top of your class.


See also:

1 Like

Thank you Nina! That was the problem!
I didn’t realize I placed the variable in the wrong place. It works now.

About the screenshot, no problem! I’ll use a formatted text from now on :slight_smile:
Thanks again

Good job! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms