M30W Programming Forum

M30W is a text-based version of Scratch

You are not logged in.

Announcement

This is the development forum for M30W (also known as Emerald, do not confuse with Emerald Programming Language).
Our Non-development forums are available here

M30W(Emerald) 0.3 is out! (Download) Requires Python 2.6 or higher.
Opal 0.3(A better command line M30W) is out! (Download) Requires Python 2.6 or higher.
M30W 0.3.6 GUI barebones (Download) Requires Python 2.6 or higher and wxPython
Diamond-2 RED2 GUI Barebones (Fancy M30W editor) s out! (Download) Requires .NET Framework 3.5 or higher, does not require Python
M30W++ GUI barebones (Java M30W) Alpha 1 is out! (Download) Requires Java.


Gershmer.net, our hosting, will close in February 2011. We have not fully decided what to do with our hosting after that, but we will tell you when we decide.

Adverts

Adverts

#1 2009-10-15 03:55:57

Magnie
> I am Ninja! <
From: Polaris, the planet
Registered: 2009-10-08
Posts: 321
Website

Changing all commands to defs

Can anyone do this?

Code:

def run():
    while line != len(program): # As long as 'line' is less than the length of the program it will run the program.
        txt.config(state=NORMAL)
        if program[line] == commands[0]: # If it is 'print'
            if (encode[line]) != "Variable": # If the string should be taken literally
                txt.insert(END, encode[line]) # Print what was typed in.
            else: # If it's a Variable
                txt.insert(END, encode2[encode3[line]]) # Print the value of the variable.
            line += 1
            txt.insert(END, "\n")
        elif program[line] == commands[3]: # If it is 'ask'
            theirInput = askstring("Question", (encode[line])) # Ask so and so then allows the user to type.
            encode2[encode3[line]] = theirInput # Put their input into a variable.
            line += 1
        else:
            txt.insert(END, "There seems to be something wrong with either your programming or our programming\n")
    onOrOff = "off" # Go back to adding commands mode.
    txt.insert(END, "\n\n")
    line = 0
    txt.config(state=DISABLED)

instead of...

Code:

while i != 1:
    while onOrOff == "off": # Add commands here
        command = raw_input("Type in a command: ")
        command.lower()
        if command != "run":
            
            if command.lower() == commands[0]: # Checks to see if it is print.
                recode = raw_input("What should your program print? ") # Allows you type type what you want for it to print.
                if encode4.count(recode) != 0: # Could this be confused with a Variable? If it is...
                    print "There is a Variable associated with this name."
                    while x == 0:
                        yourInput = raw_input("Do you want to print the value of the Variable? [Yes/No] ") # Do they want to print the value of the variable or use the text literally?
                        if yourInput.lower() == "yes": # If they want to use the variable...
                            encode3.append(encode4.index(recode)) # Say that they do
                            encode.append("Variable") # Again, say that they do
                            x=1
                        elif yourInput.lower() == "no": # If they don't   
                            encode3.append("") # Say that they don't
                            encode.append(recode)
                            x=1
                        else: # The user didn't write yes or no
                            print "Invalid Input"
                    x=0
                else: # If it can't be confused with a variable...
                    encode.append(recode)
                    encode3.append("")
                program.append(command)
                encode2.append(None)
                
            if command.lower() == commands[2]: # Checks to see if it's end.
                onOrOff = None # Makes it so you can't add a command and makes it so you can't run the program allowing it to close.
                i = 1 # Disables the whole script
                
            if command.lower() == commands[3]: # Checks to see if the command is Ask.
                recode = raw_input("What should you ask them? ") # Allows you to type what the 'question' is.
                encode.append(recode)
                program.append(command)
                while x == 0:
                    recode = raw_input("What variable would you like to put their answer into? ") # Allows you to specify what variable the user will put their answer into.
                    if encode4.count(recode) != 0: # Checks if that Variable name exists; if it does...
                        encode3.append(encode4.index(recode)) # Associate the Variable number to the line.
                        
                        x = x+1 # Get out of this dumb loop!
                    else: # If the Variable doesn't exist.
                        print "Uh-Oh, looks like there's no such Variable as "+ recode +"."
                        yourInput = raw_input("Do you want to create this Variable? [Yes/No] ") # Asks if you made a typo or forgot to make a Variable.
                        if yourInput.lower() == "yes": # If they want to create the Variable...
                            encode4.append(recode) # Do so
                            encode3.append(encode4.index(recode)) # And also add the Variable to the specifications.
                            encode2.append("none") # Sets the variable to 'none' so that no errors will occur.
                            x = x+1 # And get them out of the loop
                        # If they didn't, this loop will automatically take them back to the beginning of the variable question.
                encode2.append(None)
                x = 0
                
            if command.lower() == commands[4]: # If it is the "save" command
                yourInput = raw_input("What would you like to save this as? (DO NOT ADD AN EXTENTION) ") # Ask the user what they would like to save the program as.
                yourInput = yourInput+".emrld" # Add a extention.
                FILE = open(yourInput,"w") # Open the file as FILE for writing
                cPickle.dump(encode, FILE) # Add the necessary lists
                cPickle.dump(encode2, FILE) #   |
                cPickle.dump(encode3, FILE) #   v
                cPickle.dump(encode4, FILE) #   |
                cPickle.dump(program, FILE) #   v
                FILE.close()                # Close the file
                print "Save successful!"    # Tell the user it worked
                
            if command.lower() == commands[5]: # If it is the "load" command
                yourInput = raw_input("What file would you like to open? (DO NOT ADD THE EXTENTION) ") # Ask the user what program they would like to open
                yourInput = yourInput+".emrld" # Add an extention
                FILE = open(yourInput,"r") # Open the file as FILE for reading
                encode = cPickle.load(FILE) # Add the necessary lists
                encode2 = cPickle.load(FILE) #   |
                encode3 = cPickle.load(FILE) #   v
                encode4 = cPickle.load(FILE) #   |
                program = cPickle.load(FILE) #   v
                FILE.close()                 # Close the file
                print "Load successful!"     # Tell the user it worked.
                
            if command.lower() == commands[6]: # If it is the "add variables" command
                print "Add a Variable:"
                recode = raw_input("What would you like to call your variable? ") # Allow the user to name their variable.
                encode4.append(recode)
                encode2.append("none") # Sets the variable to 'none' so that no errors will occur.
                print "Variable created!"
                
        else: # If it is run.
            onOrOff = "on" # Makes the program run.
            txt.config(state=NORMAL)
            txt.insert(END, "\n\n")
            txt.config(state=DISABLED)
    while line != len(program): # As long as 'line' is less than the length of the program it will run the program.
        txt.config(state=NORMAL)
        if program[line] == commands[0]: # If it is 'print'
            if (encode[line]) != "Variable": # If the string should be taken literally
                txt.insert(END, encode[line]) # Print what was typed in.
            else: # If it's a Variable
                txt.insert(END, encode2[encode3[line]]) # Print the value of the variable.
            line += 1
            txt.insert(END, "\n")
        elif program[line] == commands[3]: # If it is 'ask'
            theirInput = askstring("Question", (encode[line])) # Ask so and so then allows the user to type.
            encode2[encode3[line]] = theirInput # Put their input into a variable.
            line += 1
        else:
            txt.insert(END, "There seems to be something wrong with either your programming or our programming\n")
    onOrOff = "off" # Go back to adding commands mode.
    txt.insert(END, "\n\n")
    line = 0
    txt.config(state=DISABLED)

mainloop()

Pretty much the entire program... Wowy!


- I speak IF Common -
  ~ Magnie Mozios ~

Offline

 

2009-10-15 03:55:57

AdBot
Advertisements

#2 2009-10-15 05:13:56

floppy_gunk
I Am Your Father.
From: Earth, The Milky Way (I think)
Registered: 2009-10-08
Posts: 186
Website

Re: Changing all commands to defs

Yes, I was thinking of doing that. It would clear up a lot of mess.

By the way, couldn't have you done it while you were still making the program? No offense.


Big Bob bites black bugs, but black bugs bite Big Bob back.

Offline

 

#3 2009-10-15 15:20:03

Magnie
> I am Ninja! <
From: Polaris, the planet
Registered: 2009-10-08
Posts: 321
Website

Re: Changing all commands to defs

I never knew of "defs" then. :P


- I speak IF Common -
  ~ Magnie Mozios ~

Offline

 

#4 2009-11-15 09:44:02

markyparky56
Hi...
From: Scotland
Registered: 2009-10-08
Posts: 910
Website

Re: Changing all commands to defs

O_O wow... thats big...


I am A M30Wr.
I always get the last word.

Offline

 

Adverts

Board footer

Powered by FluxBB
Hosted by PunBB-Hosting