N00b Python question.

Hey, so here is the issue. I have it so that pressing up makes the plane move up, left left, right right, and down stops the plane. My question is why does pressing down stop the plane moving left and right? I thought it would not stop the movement until I set the else statement for the goleft and goright like I did the speed. And since it does work for the left and right without these, why is it needed for the speed? Once I added the own.hidari = 0 and own.migi = 0 to elifpressdown.isPositive():, I figured that I would have to add the appropriate commands under else as well.

If anyone can explain this it would be greatly appreciated, This is my first day ever using any programming language so if you could phrase it in laymans terms it would be greatly appreciated. I followed a tutorial to get the forwards and backwards movements, and used common sense to add the left and right so if this is not the most efficient way to create movement that.s okay, i am just trying to figure out the logic of how python works and doing things spet by step like this is the best way that I find I learn new things,

Again thanks for any help you can give.

Which means that you are not ready to start blender game engine scripting.

Learn from this first:
http://www.ibiblio.org/g2swap/byteofpython/read/

Well thank you for taking an elitist attitude instead of simply saying nothing. I already said I am going through basic tutorials, I had a simple question that I am sure can be answered in a sentence or two, instead of searching through pages and pages of text hoping to possibly find an answer. That is kind of the point of these forums.It’s not like I’m asking someone to hold my hand every step of the way; I was simply wondering why something was working better than I anticipated it to. If you though my question was below you you simply could have ignored my post.

Also I apologize it I was a little rude in the last response, I really have searched through tutorials for this information but considering that it is not something that is wrong with the code but something that just seems like a logical inconsistency it really is like finding a needle in a haystack. I only ask questions when it is far more efficient to ask someone a question that I am sure can take them all of a minute to answer that spend hours combing through text hoping to find an answer to my question.

I’m an asshole, what can I say…

Anyway, the reason I didn’t want to just do everything for you is because it wouldn’t really help you understand things properly in the long run. In certain cases it’s better to learn some of this stuff on your own.

I mean especially since it’s such a small and simple script. If you really know the basics of the python syntax, then there is no reason why you can’t break this down on your own (you know how to test on your own/debug, right? -> you can just use the regular “print” statement like in any other python program. The selected output will be shown in the blender terminal/console window)

Make sure you understand how the whole “if-elif-else” condition structure works. As soon as one condition is satisfied, all others are skipped over.

Also, there is no reason to do setDLoc and addActiveActuator under every condition statement - that’s a bad structure. A better way to do things would be as explained in this tutorial:
http://www.blendenzo.com/tutBeginningBGEPython.html

PS: Lol, your manners amuse me. It’s the internet, don’t worry about “insulting” me or anything along those lines.

Actually, feel free to say “Fuck you Social” if you feel I’m acting like an elitist prick. It’s ok to do that. :smiley:

Ah. I see you met Social. He’s not really an elitist, he just comes across that way sometimes. Down deep in his heart he’s really a big fuzzy teddy bear.

Now, not to step in and disagree with anyone here, but your problem isn’t actually related to Python so much as it is related to the nature of Logic Bricks (specifically the Motion actuator).

You are only using one Motion actuator, and every time your script rewrites the dLoc properties, it is actually overwriting the old values. Now, if you were using Force or LinV, you would get a result more like what you expected, since they give an object “momentum” or “velocity” (artificial, of course). dLoc moves objects in discreet steps, though, so speed is not preserved when you change the input to the Motion actuator.

Also, if you were using four separate Motion actuators (which is completely unnecessary), you might have to send a deactivate signal to the bricks that aren’t being used in a given logic tic (a “logic tic” is one cycle through all of the Logic Bricks and Python code… about once every frame on a capable computer).

Hope that helps.

BTW, That’s a pretty decent script for your first day of programming ever. See if you can figure out how to get the plane to move diagonally when two keys are being pressed. :wink:

And now you have also met blendenzo.

…No you’re not imagining it; That is an aura of pure kindness emanating from his post (actually, all his posts do that). In a few moments you should also notice a slew of inter-dimensional portals opening up in your room.

Go ahead: pick one and take a look inside…YAY, THEY ARE ALL PORTALS TO CANDY LAND!!! Feel free to go in and stack up on delicious candy.

HOWEVER:

Note that you MUST exit candy land in no more than 10 minutes OR ELSE…well actually I don’t know why that rule exists…I think it has something to do with the ester bunny and the fact that skittles has no clue how to make a “sour” candy actually sour (the right way), but anyway, it’s a rule we must follow.

Look, it’s a bunch of portals leading to worlds made entirely out of candy…must you ask so many questions? Just avoid the butterfingers and you’ll be fine.

thank you for the response, I know the code is very inefficient, but like I said, this is like the first basic tutorial so I guess they are showing how to do things the long way so that I understand everything that;s going on. I totally understand you not wanting to baby anyone through this, I do want to figure this stuff out on my own thats why I only ask for small things like this after I have looked and did not find the answer. I tried looking at the debug but like I said, nothing was technically wrong so it was not giving me any helpful information.

oh and I’m pretty sure i could get the plane to move diagonally by changing two values at once, not sure on that in Python because I have yet to try it, but I have gotten pretty good at just using logic bricks and so far the principle doesn’t seem to be any different. my next step is going to be to try and set the movement to a usb controller (have already done a fully controllable figure with the controller including camera movement and jumping, but again this was without the use of python)

As for manners I guess it comes from a combination of having too much experience with both programmers and internet forums. I am by no means new to the game business I have been a producer for a while and have overseen teams from some very large companies, but I got fed up with the bureaucracy of it all and am stepping into the foray of indy development (hence my learning Python//C/C++/all that good crap) Most of the time if you show even the smallest hint of animosity on the internet any attempt at extracting information or having discourse just turns into an idiotic flaming war where people pick apart your grammar and semantics as if somehow it’s related to the topic in discussion. Glad to see this place is not full of idiots like that.

Social and blendenzo are two of our most accomplished and helpful Python people. Also frequently helpful are Monster and Toomai. Good luck!