General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 27th, 2011, 04:21 PM
lame student lame student is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2011
Posts: 1 lame student User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 59 sec
Reputation Power: 0
Famous Battlebot program using python coding

Famous Battlebot program using python coding
.
right now, I am stuck with the 'move module' not returning the values back to the main.

given fuel is 200. For simplicity, 1 move is 1 fuel.

for troubleshooting, I've eliminated the passing of 'currentPos' just to see if I could get the passing/returning of 'fuel' to execute.

in the main module, option 2 and 3 refer to the move module and the selection of 2 or 3 will determine which if statement within the move module will execute.

They both appear to be executing and calculating good, but the results are not being passed back to the main module, there for the fuel variable is not being modified to track the amount of fuel used.

I've looked at several online sources for possible reference or tutorials, but they mostly appear to use 'global -variable-' commands. I've tried this in several areas of the code and will either get the same results or an error about the variable being a local and a global.

I've used 'fuel = 200' and 'fuel = 200.0' and "'fuel = 200' with 'fuel = float(fuel)'" but it doesn't appear to make a difference.
I was having same issue with my 'fire module' but did a work-around where the calculation is being applied within the main module.

are you able to explain why my 'return fuel' is not being retained in the main module? This appear to be occuring with all of my modules when there is a variable to be passed into the module, modified, and then passed back to the main...

Code:
#Main Function
def main():
    #setting variables to 0
    choice = 0
    ammo = 5
    fuel = 200.0
    currentPos = 0
    targetPos = 0
    targetStatus = 0

    #main menu
    while choice != 4:
        print "1- Fire Weapon"
        print "2- Move Forward"
        print "3- Move Backward"
        print "4- Exit"
        choice = input('Enter your option ') #user input's their choice
       
        if choice == 1: # fire's weapon
            print ''
            print 'Remaining Ammo: ', ammo
            if ammo > 0:
                fire(ammo)
                ammo = ammo - 1
            else:
                print 'Out of Ammo'
                print ''
        elif choice == 2: #move module.  choice is passed to determine if fwd or bkwds
            print ''
            if fuel < 1:
                print 'Out of Fuel'
            else:
                print 'Current Position', currentPos
                print 'Available Fuel', fuel
                move(choice, currentPos, fuel)
               
        elif choice == 3: #move module.  choice is passed to determine if fwd or bkwds
            print ''
            if fuel < 1:
                print 'Out of Fuel'
            else:
                print 'Current Position', currentPos
                print 'Available Fuel', fuel
                move(choice, currentPos, fuel)
           
        elif choice == 4: #terminated program
            print raw_input('Thanks for playing ')
           
        else: #loops program for invalid entry
            print raw_input('Invalid selection, please dont fat finger the keypad ')

def fire(ammo):
    targetPos = input('How far away is the target? ')
    print ''
    print 'Weapon has been fired, calculating damage'
    if targetPos < 20:
        print ''
        print 'Target Destroyed'
    elif targetPos < 40:
        print ''
        print 'Target Partially Disabled'
    else:
        print ''
        print 'Target Unharmed'
    print ''

def move(choice, currentPos, fuel): ############# NOT RETURNING/RETAINING CURRENTPOS OR FUEL
    move = 0
    if choice == 2:
        move = input('How far foward do you want to move? ')
        if move > fuel:
            print 'Not possibe, move exceeds fuel'
        else:
            print 'You have moved foward ', move, 'ft'
            fuel = fuel - move
            currentPos = currentPos + move
            return fuel
    else:       
        move = input('How far backwards do you want to move? ')
        if move > fuel:
            print 'Not possibe, move exceeds fuel'
        else:
            print 'You have moved backwards ', move, 'ft'
            fuel = fuel - move
            currentPos = currentPos - move
            return fuel

           
#calls main
main()

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Famous Battlebot program using python coding


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap