noob question bullet script

Hey guys,

i’ve tried to make a game (with a tut offcourse :P)
and so far so good, but now if i shoot i want to see bullets.
But i don’t see them, and if i fill in the necessary code i can’t shoot either? :S
Here is the code:


cont = GameLogic.getCurrentController()

#define sensors
fired = cont.getSensor("fire").isPositive()
reload = cont.getSensor("reload").isPositive()
ray = cont.getSensor("ray")

#define actuator
recoil = cont.getActuator("play_recoil")
force = cont.getActuator("force")

#variables
isFiring = False
Ammo = getattr(cont.getOwner(), "Ammo")
Clips = getattr(cont.getOwner(), "Clips")

#define events....
if fired:
    if Ammo > 0:
        setattr(cont.getOwner(), "Ammo",Ammo - 1)
        isFiring = True
    else:
        if Clips > 0:
            setattr(cont.getOwner(), "Clips", Clips - 1)
            setattr(cont.getOwner(), "Ammo", 200) 
if reload:
    if Clips > 0:
        setattr(cont.getOwner(), "Clips", Clips - 1)
        setattr(cont.getOwner(), "Ammo", 200) 
GameLogic.addActiveActuator(recoil, isFiring)

if ray.isPositive():
  OBJECT = ray.getHitObject()
  if fired:
   pos = ray.getHitPosition()
   GameLogic.addActiveActuator(force, True)
   Bullet = force.getLastCreatedObject()
   Bullet.setPosition(pos)

If i delete everything beneath

if ray.isPositive():
    OBJECT = ray.getHitObject()

Than i’m still able to shoot, but if i add the rest of the text

if fired:
   pos = ray.getHitPosition()
   GameLogic.addActiveActuator(force, True)
   Bullet = force.getLastCreatedObject()
   Bullet.setPosition(pos)

i can’t shoot and i don’t see bullets :frowning:
What ma i doing wrong?

grtz

Did you look in the console? Thats the black window that Blender opens up. It will show you any errors.

thanks for the quick reaction :slight_smile:
yeah it says:
if fired:
^
That there is the fault on line 34 (the last part).
But i used if fired: also in the pieces above, and than it works :S

…whats the full error? “if fired” doesn’t mean much to me. I know what it means in the script, but there should be more written.

Ok sorry the error is fully:



Python error compiling script - controller "cont#CONT#1":
 File "Bullet", line 34
  if fired:
          ^
IndentationError: unindent does nog match any outer indentation level

Blender Game Engine Started


There it is

It means that your indentation is inaccurate.
Here are some steps you should try**:

  1. Select all text
  2. Format>Convert Whitespace>To Tabs

That should do it. If not, you need to redo all of the indentation in the script.

**Before you try that, try just visually checking the indentation and if it matches. Maybe you can just redo the indentation in that line.

whoohoo i love you! :slight_smile:
its working now :slight_smile:
thanks :slight_smile:

:slight_smile: No problem. Just remember to read the error next time. You can fix a lot through that.