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-11-03 17:49:31

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

Emerald - Loading Error Fix?

As I've noticed before but never thought to annouce it, but if you try to load a file that doesn't exist, it closes out of Python... But I made a fix for that. Here is the code:

Code:

# Import the cPickle module for saving and loading projects.
import cPickle
from Tkinter import *
from tkSimpleDialog import askstring
from tkMessageBox import showinfo

def aboutshow():
    print "hi"

# This is the greeting.
def greet():
    txt.config(state=NORMAL)
    txt.insert(END, "Emerald 0.3\nBy the Emerald Team\n------\nCommands:\n- Print: Puts something on the screen.\n- Ask: Asks the user a question (input).\n- Add Variable: Make a new variable.\n- Save: Save your program currently on your computer (It will save to the folder with Emerald.py)\n- Load: Load a program (It must be in the same folder as Emerald.py)\n- About: About Emerald\n<It is not Case Sensitive>\n------")
    txt.config(state=DISABLED)

# About Emerald
def about():
    showinfo("About Emerald", "Contributors:\n-Magnie\n-Coolstuff\n-Floppy_gunk\n\nPurpose:\nThe purpose of Emerald was to emulate Scratch in a textual environment. While we haven't achieved that goal quite yet, we hope to do so in the future!\n\nDifferences from 0.2 to 0.3\n-Added a GUI window!\n-Fixed a bug with printing variables")

# Make the window
root = Tk()
root.title('Emerald')

# Make the menu bar
menu = Menu(root)
root.config(menu=menu)

# The 'Emerald' submenu
emeraldmenu = Menu(menu)
menu.add_cascade(label="Emerald", menu=emeraldmenu)
emeraldmenu.add_command(label="About", command = about)
emeraldmenu.add_separator()
emeraldmenu.add_command(label="Quit", command = quit)

# Make the text box
txt = Text(root)
txt.pack()
greet()

commands = ["print","run","end","ask","save","load", "add variable"] # Commands that you can type
encode = [] # for print and ask commands
encode2 = [] # for Variable values
encode3 = [] # for specifications
encode4 = [] # for Variable names
onOrOff = "off" # A switch I never really knew what to call.
line = 0 # Shows what line the Programming Language is accessing in the program.
i = 0 # Another switch.
x = 0 # Yet another switch for the Ask command.
y = 0 # Another switch, for Variables again.
program = [] # Where all the commands will be put.
theirInput = "" # The user input from the "Ask" command
yourInput = "" # For simple yes or no questions
z = "" # String for various uses

# HOW VARIABLES WORK
# Variables in this program are much more complicated than the user makes it out to be. When you enter a
# Variable in the "Ask" command, it will find the name of that variable in encode4. After it has matched a
# String (the name of the variable you have typed in) to the number, it will associate the number with
# that in encode2 - which holds the values of the variables.
                            
# Start Program
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
                try:
                    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
                except(IOError), error:
                    print error
                else:
                    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()

I changed:

Code:

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.

to:

Code:

                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
                try:
                    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
                except(IOError), error:
                    print error
                else:
                    print "Load successful!"     # Tell the user it worked.

Using the "try" feature of Python I fixed it. :D I'm to lazy to upload a new version. :P


- I speak IF Common -
  ~ Magnie Mozios ~

Offline

 

2009-11-03 17:49:31

AdBot
Advertisements

#2 2009-11-03 19:08:26

Gershmer
Admin
From: Newton Centre, Massachusetts
Registered: 2009-10-08
Posts: 515
Website

Re: Emerald - Loading Error Fix?

No way you're too lazy.
I'm the only person who could possibly be that lazy.


http://card.ly/images/vcard-green-small.png

Offline

 

#3 2009-11-04 02:10:24

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

Re: Emerald - Loading Error Fix?

Sorry, but I fixed it on the Linux computer. So I don't have any of that stuff to upload it...


- I speak IF Common -
  ~ Magnie Mozios ~

Offline

 

#4 2009-11-04 20:48:49

Gershmer
Admin
From: Newton Centre, Massachusetts
Registered: 2009-10-08
Posts: 515
Website

Re: Emerald - Loading Error Fix?


http://card.ly/images/vcard-green-small.png

Offline

 

#5 2009-11-04 21:36:31

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

Re: Emerald - Loading Error Fix?

That's just a review, where's download?


- I speak IF Common -
  ~ Magnie Mozios ~

Offline

 

#6 2009-11-04 21:38:50

Gershmer
Admin
From: Newton Centre, Massachusetts
Registered: 2009-10-08
Posts: 515
Website

Re: Emerald - Loading Error Fix?


http://card.ly/images/vcard-green-small.png

Offline

 

#7 2009-11-04 21:50:12

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

Re: Emerald - Loading Error Fix?

Well, I don't understand how to install stuff on Linux. :P


- I speak IF Common -
  ~ Magnie Mozios ~

Offline

 

#8 2009-11-04 22:22:46

Gershmer
Admin
From: Newton Centre, Massachusetts
Registered: 2009-10-08
Posts: 515
Website

Re: Emerald - Loading Error Fix?

http://gftp.seul.org/gftp_2.0.19-1_all.deb

Download this file.

Open Terminal.

type "sudo dpkg -i <location>gftp+2.0.19-1_all.deb"
(no quotes)

Not sure which flavor of Linux you have, but some have a program built-in called "Package Installer" where you can just double-click DEBs and they install.






I would try seeing if you have package installer first.


http://card.ly/images/vcard-green-small.png

Offline

 

#9 2009-11-05 00:23:56

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

Re: Emerald - Loading Error Fix?

I have Ubuntu.


- I speak IF Common -
  ~ Magnie Mozios ~

Offline

 

#10 2009-11-05 00:47:04

Gershmer
Admin
From: Newton Centre, Massachusetts
Registered: 2009-10-08
Posts: 515
Website

Re: Emerald - Loading Error Fix?

Magnie wrote:

I have Ubuntu.

Then you have Package Installer.
http://gftp.seul.org/gftp_2.0.19-1_all.deb
Download the deb^
Double click the file.


http://card.ly/images/vcard-green-small.png

Offline

 

Adverts

Board footer

Powered by FluxBB
Hosted by PunBB-Hosting