Bowling game

My first python game is going to be a basic ten-pin bowling game. I’ve got a way to aim, spin, etc with basic logic blocks, but for score-keeping i have to your python. I was thinking a touch sensor toward the bowling alley with it evaluating to negative if the pin is knocked down. at the moment my code is.

import GameLogic as GL

cont = GL.cont.getCurrentController()
own = cont.getOwner()

pinno = 10
pins = 10 - pinno
touch1 = cont.getSensor("touch1")



if touch1.isPositive():
    pinno -= 1
    
    
    else
        

my testing code which is a very much WIP is

import GameLogic

cont = GameLogic.getCurrentController()
own = cont.getOwner()

touch = cont.getSensor("touch")
#act = cont.getActuator("act")
pinno = 10


if touch.isPositive():
    #GameLogic.addActiveActuator(act, True)
    pinno -= 1
    #print pins
    print pinno
    #else:
        
        
pins = 10 - pinno

i want something to show how many pins i have knocked down.

i’ll upload the blends later but i can’t right now. synthasite is ofline

Luckily, this is very simple. Follow this Tutorial http://bgetutorials.wordpress.com/2007/11/07/how-to-get-realtime-text-in-blender/ (Very Simple, fast tutorial)Notice that whatever the properties value is, that is what the text displays. THen CHange Your Code.


import GameLogic

cont = GameLogic.getCurrentController()
own = cont.getOwner()

touch = cont.getSensor("touch")
pins = 10


if touch.isPositive():
    pins = pins - 1
    own.text = str(pins)
        
        


Note that The Above assumes your text object is called “text”.

Yeah thanks thats a big help. Got that working now. Trouble is that i’m having trouble with the touch sensors. ATM the touch sensor variable is in the same script as the

own.text = str(pins)

. I dont’ really think that’s the right way to do it. Also the

if touch.isPositive):
                       pinno -= 1

doesn’t work that well. In fact it doesn’t work at all.

also the console asks for a touch sensor for the text object. Is there a way to reference things more exactly. maybe not using

cont = GameLogic.getCurrentControler():

and

own = cont.getOwner():

also if this was not possible, is there a way to change something from one script, to another script.

I had an idea for how to have the counter working. I figure if i add a text file which has the score in it and if i add different scripts for every pin and get them to - 1 from the file if touch is positive i can do it. Needs some fleshing out but i’ll post back here if i can’g get it to work.

i just had a bit of a problem. I tried the above idea with this script.

import GameLogic as GL

cont = GL.getCurrentController()
own = cont.getOwner()

pinss = "10"

text_file = open("pinss.txt", "a+")
text_file.write(pinss)
print text_file.read()
text_file.close()

linked to an always sensor called “touch” on the first pin

My computer started beeping (from the case not the speakers) and the console came up with this.

  ♠           ♦   e   ♠
   ♦   i              ♦   â               ♠   o   ╔   Ç╗Γ☺        ☺
  ♦   e   ♦       ♂   ♦   i             ♦   Z                      ♦   e   ♦
   ♀   ♦   i
   ♦   Z   ♀           ♦   e           ♫   ♦   d   ♦               ↓
   ♦   e   ♂           ♦   d   ♦               ↓               ♦   d   ♣
       §               ♦   e   ♀               ¶                   ↨
   ♦   e                   ♦   d   ♥               ↓               ♦   e   ♂
       ♦   d   ♥               ↓               ♦   d   ♣               §
       ♦   e   ♀               ¶                   ↨               ♦   e
           ♦   d   ♠               ↓               ♦   e   ♂           ♦   d   ♠
               ↓               ♦   d   ♣               §               ♦   e   ♀
           ♦   d   ♦           ♦   d              ♦   â   ♥           ♠   o   ¶
           ♦   d   ♦           ♦   d            ♦   â   ♥               ♀











                                                                    π A☺ô►♀☻X╡τ☺
 2Φ☺    ♥           ♠                              ♀           ☼           ↕
       §           ↑           ←           ▲           !           $           '
           *           -           0           3           6           9
   <           ?   @           C           F           I           L           O
           R           U           X           [           ^           a   b
       e           h   i           l   m           p   q   r           u
   x   y           |           ⌂   Ç           â   ä           ç   ê   ë
   î           Å   É           ô           û   ù           Ü   ¢           ₧   ƒ
   á           ú           ª           ⌐           ¼           »           ▓
       ╡           ╕           ╗   ╝           ┐           ┬           ┼
   ╚           ╦           ╬   ╧           ╥   ╙           ╓           ┘
   ▄           ▀   α           π   Σ           τ           Ω   δ           ε   ∩
           ≥           ⌡   ÷           ∙   ·           ²            ☺  ☺☺
   ♦☺  ♣☺        ☺      ☺          ♀☺      [ ê  ► ☻P♦Z☺P♦Z☺






ß☺X╡τ☺        ♦   ♦   d   ☺           ♦   k               ♦   Z               ♦
  e           ♠   ♦   i   ☺           ♦   â               ♦   Z   ☻           ♦
  e   ☻          ♦   i   ♥           ♦   â               ♦   Z   ♦           ♦
 e   ☻        ♦   i   ♣           ♦   d   ☻           ♦   â   ☺           ♦   Z
  ♠           ♦   e   ♠
   ♦   i              ♦   â               ♠   o   ╔   Ç╗Γ☺        ☺
  ♦   e   ♦       ♂   ♦   i             ♦   Z                      ♦   e   ♦
   ♀   ♦   i
   ♦   Z   ♀           ♦   e           ♫   ♦   d   ♦               ↓
   ♦   e   ♂           ♦   d   ♦               ↓               ♦   d   ♣
       §               ♦   e   ♀               ¶                   ↨
   ♦   e                   ♦   d   ♥               ↓               ♦   e   ♂
       ♦   d   ♥               ↓               ♦   d   ♣               §
       ♦   e   ♀               ¶                   ↨               ♦   e
           ♦   d   ♠               ↓               ♦   e   ♂           ♦   d   ♠
               ↓               ♦   d   ♣               §               ♦   e   ♀
           ♦   d   ♦           ♦   d              ♦   â   ♥           ♠   o   ¶
           ♦   d   ♦           ♦   d            ♦   â   ♥               ♀











                                                                    π A☺ô►♀☻X╡τ☺
 

2Φ:slight_smile: :heart: :spades: ♀ ☼ :arrow_up_down:
§ ↑ ← ▲ ! $ ’
* - 0 3 6 9
< ? @ C F I L O
R U X [ ^ a b
e h i l m p q r u
x y | ⌂ Ç â ä ç ê ë
î Å É ô û ù Ü ¢ ₧ ƒ
á ú ª ⌐ ¼ » ▓
╡ ╕ ╗ ╝ ┐ ┬ ┼
╚ ╦ ╬ ╧ ╥ ╙ ╓ ┘
▄ ▀ α π Σ τ Ω δ ε ∩
≥ ⌡ ÷ ∙ · ² :slight_smile: :slight_smile::slight_smile:
:diamonds::slight_smile: :clubs::slight_smile: :slight_smile: :slight_smile: ♀:slight_smile: [ ê ► :slight_smile:P​:diamonds:Z​:slight_smile:P​:diamonds:Z​:slight_smile:

ß:slight_smile:X╡τ:slight_smile: :diamonds: :diamonds: d :slight_smile: :diamonds: k :diamonds: Z :diamonds:
e :spades: :diamonds: i :slight_smile: :diamonds: â :diamonds: Z :slight_smile: :diamonds:
e :slight_smile: :diamonds: i :heart: :diamonds: â :diamonds: Z :diamonds: :diamonds:
e :slight_smile: :diamonds: i :clubs: :diamonds: d :slight_smile: :diamonds: â :slight_smile: :diamonds: Z
:spades: :diamonds: e :spades:
:diamonds: i :diamonds: â :spades: o ╔ Ç╗Γ:slight_smile: :slight_smile:
:diamonds: e :diamonds::diamonds: i :diamonds: Z :diamonds: e :diamonds:
:diamonds: i
:diamonds: Z ♀ :diamonds: e ♫ :diamonds: d :diamonds:
:diamonds: e ♂ :diamonds: d :diamonds::diamonds: d :clubs:
§ :diamonds: e ♀ ¶ ↨
:diamonds: e :diamonds: d :heart::diamonds: e ♂
:diamonds: d :heart::diamonds: d :clubs: §
:diamonds: e ♀ ¶ ↨ :diamonds: e
:diamonds: d :spades::diamonds: e ♂ :diamonds: d :spades:
:diamonds: d :clubs: § :diamonds: e ♀
:diamonds: d :diamonds: :diamonds: d :diamonds: â :heart: :spades: o ¶
:diamonds: d :diamonds: :diamonds: d :diamonds: â :heart:

                                                                π A☺ô►♀☻X╡τ☺

2Φ:slight_smile: :heart: :spades: ♀ ☼ :arrow_up_down:
§ ↑ ← ▲ ! $ ’
* - 0 3 6 9
< ? @ C F I L O
R U X [ ^ a b
e h i l m p q r u
x y | ⌂ Ç â ä ç ê ë
î Å É ô û ù Ü ¢ ₧ ƒ
á ú ª ⌐ ¼ » ▓
╡ ╕ ╗ ╝ ┐ ┬ ┼
╚ ╦ ╬ ╧ ╥ ╙ ╓ ┘
▄ ▀ α π Σ τ Ω δ ε ∩
≥ ⌡ ÷ ∙ · ² :slight_smile: :slight_smile::slight_smile:
:diamonds::slight_smile: :clubs::slight_smile: :slight_smile: :slight_smile: ♀:slight_smile: [ ê ► :slight_smile:P​:diamonds:Z​:slight_smile:P​:diamonds:Z​:slight_smile:

a

                                                                π A☺ô►♀☻X╡τ☺

2Φ:slight_smile: :heart: :spades: ♀ ☼ :arrow_up_down:
§ ↑ ← ▲ ! $ ’
* - 0 3 6 9
< ? @ C F I L O
R U X [ ^ a b
e h i l m p q r u
x y | ⌂ Ç â ä ç ê ë
î Å É ô û ù Ü ¢ ₧ ƒ
á ú ª ⌐ ¼ » ▓
╡ ╕ ╗ ╝ ┐ ┬ ┼
╚ ╦ ╬ ╧ ╥ ╙ ╓ ┘
▄ ▀ α π Σ τ Ω δ ε ∩
≥ ⌡ ÷ ∙ · ² :slight_smile: :slight_smile::slight_smile:
:diamonds::slight_smile: :clubs::slight_smile: :slight_smile: :slight_smile: ♀:slight_smile: [ ê ► :slight_smile:P​:diamonds:Z​:slight_smile:P​:diamonds:Z​:slight_smile:

Blender Game Engine Finished



very confusing. 
separated due to length restrictions

I dont’ really think that’s the right way to do it. Also the Code:
if touch.isPositive):
pinno -= 1

doesn’t work that well. In fact it doesn’t work at all.

python does not work like that. It uses indents to check for loops and what not. And you 2 parenthesis to call a method like this.


if touch.isPositive():
    pinno -= 1

If that does not work, try using a collision sensor. if that still does not work try using


if touch.isTriggered():
    pinno -= 1
 

And if that still does not work just upload the .blend.
and about what you said it should not be x = x -1, it should be x -= 1. You can do that either way with the same result, I just prefer the former because of more control if you want to put a second variable in there. And with the error messages… well no idea!

Good Luck!

I’ve kinda lost where i’m going with the programming at the moment. I’ve gotten confused. Here is the blend in a .rar file ( tesbowling is the test version, bowling2 is the working version i think. test.blend is a simple file for basic testing purposes)
http://fake.synthasite.com/resources/blender/bowlinggame/bowling2.rar

Maybe it beeped because of this?
text_file = open(“pinss.txt”, “a+”)
I haven’t ever seen that one… try just w
That beeping has already happened to me 2 times with python. Once when I was doing a mouselook script.
If it beeps again try not to reset your computer but to kill blender.exe via task manager.

got a new version. started from scratch. I’ll append the pins and stuff in later, this is just for the scripting. OK.

the python has been rewritten. problem is i think i have to use a loop and i’m not very good at loops

here is the .blend

http://fake.synthasite.com/resources/blender/bowlinggame/bowling3.blend

oh yeah and i don’t think i reset my computer, i just killed blender via blender console. Just clicked on the “X”.

Ok, the last one you uploaded crashed every time, idk what you did, and I tried deleting all the scripts but that did not help so, I will try downloading your other one and fixing it.

EDIT: After trodging throught the other one… I can say I have no idea! Basically I can not even follow what is going on… Try different things and be creative!

really? that’s confusing. hey is this the correct syntax for a while loop. this loop will count the pins and keep updating the score thingo.

import GameLogic as GL

cont = GL.getCurrentController()
own = cont.getOwner()

pinno = 10
pins = 10

loop = 1

own.Text = str(pins)
sens = cont.getSensor("sensor")
touch = cont.getSensor("touch")

#if touch.isPositive():
	#pins -= 1
	#loop -= 1
	
pinno -= pins

while loop == 1:
	own.Text = str(pins)
	if touch.isPositive():
		pins -= 1
		loop -= 1

that’s the current counter code. the only other scripts in use are blast.py (which is Cyborg_ar’s) and speed.py (which is Cyborg_ar’s)

updated the blend same link as before but anyway
http://fake.synthasite.com/resources/blender/bowlinggame/bowling3.blend

please i need this for mid-next week. I could present it as it is, but i’d prefer if it was finished.

Hi Fake,

I’ve read your posts and you don’t say what part of the blend you want help with. It would be nice to know what is giving you problems. What is it supposed to do? What is it doing instead?

So, I decided to fix the speed.py. It was writing error messages to the console window like crazy.

The original speed.py

import GameLogic
import Blender
 
cont = GameLogic.getCurrentController()
own = cont.getOwner()
clk = cont.getSensor("clk2")
 
#scene = GameLogic.getCurrentScene()
cube = Blender.Object.Get("Cube")

if clk.isPositive():
    cube.prop = own.getLinearVelocity(1)[1]

I removed the import Blender. The way you mixed the Blender and GameLogic code was causing the error messages. Besides, there isn’t any need to import Blender and it would prevent you from creating a working runtime.

I also changed the getLinearVelocity for the bowling ball. You had it set up to get the Local Y velocity on a spinning ball. I changed it to World Y velocity. In this case, World Y will give you the speed of the ball.

Fixed speed.py

import GameLogic
 
cont = GameLogic.getCurrentController()
own = cont.getOwner()
clk = cont.getSensor("clk2")
 
scene = GameLogic.getCurrentScene()

objList = scene.getObjectList()

cube = objList["OBCube"]

if clk.isPositive():
    cube.prop = own.getLinearVelocity(0)[1]

Clark

i have problem with touch sensor. too bad… i just think i can fix the counter for you.
http://g.imagehost.org/download/0142/bowlingALL_blend

i add some script that i think should work if i got touch sensor working.

  1. init script that will define initial score
  2. added bool property to pin so that if the pin fall down, the property will set to true
  3. added property sensor to pin, if pin bool property == true. run counter.py
  4. counter.py just add 1 to initial score.
  5. lastly scoreboard script that will change the scoreboard text to current score.