Some Python help/tutoring?

Hey guys,
I’m still trying to learn Python, I got O’reilly’s excellent Learning Python book, but I still need help doing programming for the GE. There are no good tutorials on the Internet that I’ve found.

I’m working on a game idea that would partially involve a cursor, and I’ve done up a nice cursor that’s moved with IPOs, as you can see in this mock-up file:
http://www.gorilla3d.com/plantperson/property_cursor.blend

However, reverse-engineering is a terrible way to learn programming, and I’ve been unable to figure out how to make the mouse movement affect the property values. The script should reduce or increase the property depending on which way the mouse is moved, with restrictions to keep the value from exceeding 50 or going below 1.

My request is this: could someone,
A. Make a script which does this, and,
B. Show me how it works

The B is important because, before I can learn this, I have to understand how things work. Understanding the workings of the scripts I already use will help.

Thanks in advance!

Your code should look like this:

 
from GameLogic import *
Cont = getCurrentController()
Own = Cont.getOwner()
Xmov = Cont.getSensor("xmov")
#You had everything above here right
Xpos = Xmov.getXPosition() #Stores the mouse's X position as the variable Xpos
Own.position = Xpos #Sets the position property of the Object identified as Own to equal Xpos

Just post if my comments in the code aren’t enough for you to understand it.

That’s fast service! I’ll review what you did and get back to you.

I did a python tutorial not so long ago:

http://blenderartists.org/forum/showthread.php?t=80826

I tried to explain some basic concepts. I had pretty good feedback, so it should help anyone who is just starting out with BGE PY.

Hey Plant,

I tried MagicMan’s changes, and they didn’t do the trick, so I thought I’d give it a go. Here’s the code that works:

from GameLogic import *
import Rasterizer

Rasterizer.showMouse(1)

Cont = getCurrentController()
Own = Cont.getOwner()
Xmov = Cont.getSensor("xmov")
Ratio = Rasterizer.getWindowWidth()/50

XPos = Xmov.getXPosition()
Own.position = XPos/Ratio

“Rasterizer.showMouse(1)” makes the system cursor appear on screen. I only did that so that I could be sure the custom cursor was accurately following the system cursor. Once you’re satisfied that it is, you can remove that line from the code.

Explanation of changes to code: You will need to get the window width, so you must import Rasterizer.

Since your game may be played at various resolutions, you should find out how many pixels each frame of your IPO should represent at the given resolution. Find the window width and divide it by the number of frames (50 in your case) to get this value (the “ratio”).

Now get the X-position of the system cursor (it returns a value relative to the Blender window) and set the “position” variable to the correct IPO frame (the X-position divided by the ratio).

Something to note: I have never been able to get a custom cursor to follow the system cursor with 100% accuracy. You’ll probably just have to settle for “close enough.”

blendenzo, thank you, it is perfect!

Social, thank you for the link, I will check it out as soon as I can