Pen_color = 1
def pen_color(“colour”):
global pen_color
if(“colour”=black)
pen.set_pen_color(BLACK)
def when_started1():
drivetrain.drive_for(FORWARD,1000,MM)
pen.move(DOWN)
vr_thread(when_started1())
This says it has a sytax error on the 2nd line. What’s happening
That is weird, I tryed ur code in Vr code and it is saying a veriable is incoreect. Me confused
Yeah, thats what happened to me
It is saying the Parentheses is incorrect
It’s incorrect Python, what do you want that code to do Milo ?
7 Likes
Im trying to get a function that I can just type in the color, or type random to get the pen as a random color.
I know both Python and Java
That can’t happen in Vex Vr code, that can only happen in the python app
In the function prototype, you should use the name of the parameter rather than a string, i.e.:
def set_pen_color_with_string(color):
if (color == "black"):
pen.set_pen_color(BLACK)
# etc...
color
can be the name of a variable or function parameter, "color"
is the literal string “color”, the two aren’t interchangeable.
3 Likes
yea, there seem to be some issues using set_pen_color inside a function, we will look into it.
2 Likes
ok, seems there is some issue with a function called “pen_color”, but this works
# Library imports
from vexcode import *
def set_color(color):
colors = [RED, GREEN, BLUE, BLACK]
if color == "random":
x=random.randint(0,3)
brain.print(x)
pen.set_pen_color(colors[x])
# Add project code in "main"
def main():
pen.move(DOWN)
for i in range(0, 10):
set_color("random")
drivetrain.drive_for(FORWARD, 100, MM)
# VR threads — Do not delete
vr_thread(main())
5 Likes
My Robotics teacher has had us doing VR for us to get used to coding in text. However, the same thing happens to us some too. And sometimes, it says there’s a Syntax Error on line 19, but there is no line 19. So there’s that thing happening to me as well… VR has unexplainable problems: phasing through walls and syntax errors and stuff.
1 Like
Thanks! I didn’t see this until now, so I just ended up asking Noah from 10851B what was wrong.
2 Likes
jpearman:
def set_color(color):
colors = [RED, GREEN, BLUE, BLACK]
if color == "random":
x=random.randint(0,3)
brain.print(x)
pen.set_pen_color(colors[x])
How about instead of picking an index from the list using a random.randint
, you use a random.choice
def set_color(color):
colors = [RED, GREEN, BLUE, BLACK]
if color == "random":
x=random.choice(colors)
brain.print(x)
pen.set_pen_color(x)
Python is great! Yeah!
6 Likes
I love python, it is the first laguege I learned. I would recommend python for people who want to start progrmming
2 Likes
That works as well, it’s my C heritage showing…
7 Likes
I got it to work. (edit: It doesn’t actually change the color, but it does print it out on the brain.)
2 Likes