kivy switch_to screen on if statement doesn't work - python-3.x

I could REALLY use your help with this one.
I'm trying to make a sort-of voice command operated menu for a toddler's learning app and kivy is giving me a headache
all of my screens are correctly defined and load as intended if the buttons are pressed but the voice commands, even though they register correctly and carry over their variables as intended they don't seem to have the desired effect when asked to act upon ScreenManager when the if statement is fulfilled
def on_enter(self):
....
Command.start()
Command.introMenu()
......
if Command.sel == "shapes":
ScreenManager().switch_to = "shapes"
elif Command.sel == "colours":
ScreenManager().switch_to = "colours"
......
else:
pass
the variable Command.sel is captured from a dependency, defined as a string and carried correctly as far as I can tell from the variables view in debugging
yet even though everything seems to be in order (in fact no error messages appear at all) the desired screen is not called when the if condition is met
what am I doing wrong here???
full code here
(please ignore the Greek bits in the code... it's just strings, imagine it's any other language for that matter...)
thank you!

issue resolved
correct command was
self.parent.current = "your_screen_name"
answer (eventually) found here

Related

Discord.js message includes

Hi im currently adding some new features to a bot and it's been going great with some amazing progressions each day. I ran into an issue that i can't seem to solve even though i feel like the solution is right in front of me. In my code i have an if statement to check if a user has more matches won than 22 in the database, if so they are allowed to equip a certain background if not it returns an error message. I tried to do another if statement to check if a certain user is trying to run the command by matching their discord ID and for some reason it runs both the if statements when doing either command even though i used message.content.includes to specify what arguments it should look for in the command. Any help would be appreciated
According to the mozilla docs:
The comma operator (,) evaluates each of its operands (from left to right) and returns the value of the last operand.
This means that only the second operand in each if statement is being returned, ignoring message.content.includes().
Changing the , to && should fix the issue.
source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator

Python simple game with pygame - limits

I made a simple game with python using the Pygame library but when I finished I just noticed that I forgot something. LIMITS
I am pretty new at python and I tried with
if player_pos[1] <= 600:
pygame.K_DOWN = None
*player_pos[1] is the y player's position
*600 is the display's limit
But then, the "down" key just stopped working so I just erased that lines.
You can't (or shouldn't try at least) to turn the input into None. Just use a logical test to decide if you want to move further...
if key_pressed == 'K_RIGHT': (or whatever syntax you use to catch keypress..)
if player_pos[1] < limit:
# update the player position
else:
pass
#JeffH has already suggested the a way to fix your code. I just wanted to make sure you understood why what you did caused problems and to point out the convention for constants. Not understanding and using that naming convention will make it more difficult for you to understand other code, and will complicate others trying to read your code.
pygame.K_DOWN is intended to be a defined constant, it is not an input or a control variable. You should absolutely not change it.
Python does not have true constants that enforce not being able to change them, so it is handled by convention. Variables that are intended to be constants by convention use all uppercase names, like K_DOWN and you are just not supposed to change them. As you discovered things may break or behave weirdly if you do.
In your case 'the down key stopped working' because the constant used to check it no longer contained the right value anymore. Pygame will give you the keycode for the down arrow key (the number 274 when I print it on my system) but you have assigned None to the constant that you are supposed to compare that value with to determine if it is the down arrow key, so that comparison will now fail.
That is why it stopped things working.

my questions is about code in GDscript (language programing in godot engine)

sprite (attack) is not working in case :
if Input.is_action_just_pressed("ui_attack"):
$Sprite.play("attack")
but in case:
if Input.is_action_pressed("ui_attack"):
$Sprite.play("attack")
it's working !!!!
what is the solution code pleas?!! Because I want one click on the keyboard to work of sprite...
Have you tried using if event.is_action_pressed("ui_attack"): instead?
I've found that event works better than Input if I only want one action after a button press and not multiple.
If it still doesn't work, try adding if event.is_action_released("ui_attack"): afterwards. You may have to put an additional command afterward to make the code acceptable to the engine, such as print("Key Released"). In my case, it never ended up printing anything to console, but it did only give me one action per button press.
I am assuming this is the question you were looking for an answer to. If not, please disregard, I have been awake all night and am prone to confusion.
EDIT: I forgot to add that it must be in a func _input(event) function to work properly. I've included a simple example that prints text to the console once per press of the left button. See below:
extends Node2D
var text = PrintText()
func PrintText():
return("Print Text Once")
func _ready():
pass
func _input(event):
if event.is_action_pressed("ui_left"):
print(text)
(P.S. I only discovered Godot in the last week or so, but have been crash-coursing myself ever since. I love the engine, but if my understanding comes off as "basic", forgive me.)

python error-can only join an iterable

I am making a program in pygame and I am trying to create with buttons where the user can enter their name. So basically when ever they click on the letter, then it puts that letter into a list. I recreated with about the same variables as in my game and got the same error. So if we can fix this, then I can fix my game. I am using functions so that is why you see the global thing as that is needed. Here is the code. I have looked at other forums btw but nothing that is the same as mine.
import glob
unknown=[]
def bob():
global unknown
a=('a').upper()
unknown=unknown.extend(a)
unknown=','.join(unknown)
bob()
Again, this is basically what is in my code except for the name of the function and the name of the list, other than that it is the same. The name doesn't matter though. Thanks in advance.

pygame input and image

I am new to pygame and i am having a problem with something i am working on.
f=input('blahblablb')
if f =='badafd':
x=input'ajdfkladjsl'
elif f ==...
so i have this input and variable but later when i use the variables
class A(pygame.sprite.Sprite):
i made a class and had the code in it for an image and it appeared fine
i also put it in a group and it appeared fine
later i added
if f=='badafd':
all_sprites_list.add[A]
but the image appears even though f does not equal badafd
please tell me the problem and i will include the main loop because that might be the problem
while True:
all_sprites_list.update()
all_sprites_list.draw(screen)
pygame.display.update()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if there is anything i could improve could you also tell me
You don't really have enough code, but I have some ideas (I can update the answer if more code is included). I am guessing that you are using an inputted string as a spite attribute. If this is the case, you could just assign the variable in initialization using input. If you want to assign this to all of them, just take the input, and then iterate through the list, like so:
for sprite in <sprite_group>:
sprite.<attribute> = <input>
Another important thing is that you should really be using raw_input. This probably won't affect your performance, but raw_input really is much better. To get an input string, just use this code:
myvariable = raw_input("enter text input: ")
this will give you a prompt of "enter text input: " and will return the text that is inputted.

Resources