How to start a class as soon as the program starts?

Put your programming skills to the test in these challenges.

How to start a class as soon as the program starts?

Post by ghostheadx2 on Fri May 22, 2015 4:26 pm
([msg=88155]see How to start a class as soon as the program starts?[/msg])

So, I'm making a two file program. However, I'm trying to be able to run the room1() class as soon as I start the program. What do I define to immediately start the opening level as soon as I run the program. Here is my code so far. It's not nearly done:

Code: Select all
class room1():   
   def roomOneOptions():
      option=raw_input("Type A, B, or C >>")
      if option=="A":
         room2()
      elif option=="B":
         room2()
      elif option=="C":
         alligators()
      else:
         print "Try typing in a real room letter."
         roomOneOptions()
      
   def intro():
      print "You wake up in a weird underground building. Your in a room"
      print "and your on a bed. There's a lock on the door. Can you get out?"
      print "There's a message on one of the three doors. Maybe you should pick"
      print "it up."
      a=raw_input("Yes or No >>")
      if a=="No":
         print "You wait in the room looking around until you starve to death."
      elif a=="Yes":
         message()
      
   def message():
      print "You pick up the message. It reads:"
      print """DEAR TEST SUBJECT:
      
      YOU HAVE BEEN KIDNAPPED. YOU ARE BEING USED FOR AN EXPERIMENT.
      YOU HAVE NO CHOICE BUT TO TRY TO GET OUT. THE WAY IT WORKS IS THERE ARE
      TEN HUMANS IN THIS EXPERIMENT WHO ARE TEST SUBJECTS. THEN THERE'S ME
      THE CONDUCTOR. YOU WILL NEVER FIGURE OUT MY NAME. MY HYPOTHESIS IS THAT
      EXACTLY ONE SUBJECT WILL LEAVE ALIVE. I'M EXPERIMENTING TO SEE WHO IT WILL BE.
      
      SINCERELY,
      
      CONDUCTOR
      
      P.S. I'M A PSYCHO"""

class room2():
#room two hasn't been made yet. I'm focused on room1.


I just want to run a function from room1() or the whole class when it starts. I think this works but it might cause problems. Tell me what you think of something this obvious:

Code: Select all
def start():
    while True:
        room1()
ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: How to start a class as soon as the program starts?

Post by LoGiCaL__ on Sun May 24, 2015 2:56 am
([msg=88163]see Re: How to start a class as soon as the program starts?[/msg])

Are you familiar with constructors?
User avatar
LoGiCaL__
Addict
Addict
 
Posts: 1080
Joined: Sun May 30, 2010 12:33 pm
Blog: View Blog (0)


Re: How to start a class as soon as the program starts?

Post by ghost107 on Mon May 25, 2015 2:44 pm
([msg=88182]see Re: How to start a class as soon as the program starts?[/msg])

You should read abut OOP(Object Orientated Programming), because your code is the same as not having the line with the word class there.

https://docs.python.org/3/tutorial/classes.html
http://code.tutsplus.com/articles/pytho ... -net-21476

Video:
https://www.youtube.com/watch?v=pxbdnrj ... KWAJibUGi6


Isn't this forum section for HTS Missions -> Programming. You know there is another section of the forum called Computers -> Programming, usually this section is for the programming challenges.
viewforum.php?f=36
User avatar
ghost107
Poster
Poster
 
Posts: 321
Joined: Wed Jul 02, 2008 7:57 am
Blog: View Blog (0)


Re: How to start a class as soon as the program starts?

Post by ghostheadx2 on Tue May 26, 2015 11:51 pm
([msg=88199]see Re: How to start a class as soon as the program starts?[/msg])

I'm not familiar with them in python. I've heard of them in other languages.
ghostheadx2
Contributor
Contributor
 
Posts: 728
Joined: Wed Nov 19, 2014 1:19 am
Blog: View Blog (0)


Re: How to start a class as soon as the program starts?

Post by LoGiCaL__ on Wed May 27, 2015 12:25 pm
([msg=88208]see Re: How to start a class as soon as the program starts?[/msg])

ghostheadx2 wrote:I'm not familiar with them in python. I've heard of them in other languages.


I'm with ghost107, you should definitely familiarize yourself with the OOP paradigm especially with python. With that being said this may help you on your way: http://www.dotnetperls.com/class-python
User avatar
LoGiCaL__
Addict
Addict
 
Posts: 1080
Joined: Sun May 30, 2010 12:33 pm
Blog: View Blog (0)



Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron