I added you to the sourceforge project, now you can post code with svn. (there are some instructions in the old m30w topic on how to do that). I don't really know though what you can do at this stage. Try to get yourself familiar with the code, you can try to stop the stage from redrawing itself when the frame is resided.
Offline
Nice work so far! Could you implement the design of executing the scripts? That way I can work on adding the "blocks" and making myself useful.
Offline
You could name the methods like this:
i_add_i(a, b): # Adds two numbers together i_sub_i(a, b): # Subtracts b from a join_s_s(a, b): # Joins two strings together
i = integer (at least, that's what it represents)
s = string
b = boolean
Offline
Magnie wrote:
You could name the methods like this:
Code:
i_add_i(a, b): # Adds two numbers together i_sub_i(a, b): # Subtracts b from a join_s_s(a, b): # Joins two strings togetheri = integer (at least, that's what it represents)
s = string
b = boolean
Yes, but I still get ugly exceptions list when converting from/to kurt.
Offline
roijac wrote:
I still haven't figured out how I want to add the methods - unlike squeak you can't have neither ':' in a method name, nor method names like '&' or '+'.
Try using a dictionary to convert command names to method names, and then the methods can be Python methods. And strip the colons (or maybe replace 'em with underscores?). Something like this:
command = 'wait:elapsed:from:' # parameter
SPECIAL_NAMES = {
'+': 'add',
'&': 'and',
# ... etc
}
method_name = SPECIAL_NAMES.get(command, command) # use command as default
method_name = method_name.replace(":", "_").rstrip("_")
method = getattr(sprite, method_name) # Note this throws AttributeError if the method doesn't exist
method(*args) # ...
Offline
roijac wrote:
That, or I use decos
How would you use decorators? I don't think they would be better.
Offline
roijac wrote:
I added you to the sourceforge project, now you can post code with svn. (there are some instructions in the old m30w topic on how to do that). I don't really know though what you can do at this stage. Try to get yourself familiar with the code, you can try to stop the stage from redrawing itself when the frame is resided.
Thanks! Can you post a link to the old M3OW topic?
Offline
I'm writing this on mobile, but anyway...
class Sprite: blocks = {} def block(name): def func(method): blocks[name] = method return func def __getattr__(self, key): try to return from self.blocks @block('+') def _ (a, b): return float(a) + float(b)
It'll work because getattr accepts any strings (even empty ones). Anyway a decorate on all blocks is extremely useful for debugging.
@davidkt, try searching
Edit: bbcode is case eensitive?!
In fact, I really like this approach
Last edited by roijac (2013-04-23 18:57:09)
Offline
roijac wrote:
I'm writing this on mobile, but anyway...
Code:
class Sprite: blocks = {} def block(name): def func(method): blocks[name] = method return func def __getattr__(self, key): try to return from self.blocks @block('+') def _ (a, b): return float(a) + float(b)It'll work because getattr accepts any strings (even empty ones). Anyway a decorate on all blocks is extremely useful for debugging.
@davidkt, try searching
Edit: bbcode is case eensitive?!
In fact, I really like this approach
I agree, decorations is probably best and probably easiest in the long run. I was thinking you could use a dictionary {'+':i_add_i} (i_add_i being the function, since you can "move it around" if you drop the parentheses), but decorators would make it easier to add new blocks in the future.
Offline
roijac wrote:
@davidkt, try searching
You never said M30W used to be called Emerald! Now; scrolling through a bunch of chatting between Magnie, markyparky56 and coolstuff; I still can't find the post. What's the post number?
Also, should I start implementing the green flag?
Offline
I can't install on Ubuntu 12.10 64-bit. It downloads the M30W files fine, but cannot install them. Here is the error message:
Installing collected packages: M30W, kurt, construct, PLY
Running setup.py install for M30W
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: option --single-version-externally-managed not recognized
Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/darkness3560/build/M30W/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-2GCZM5-record/install-record.txt:
usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: -c --help [cmd1 cmd2 ...]
or: -c --help-commands
or: -c cmd --help
error: option --single-version-externally-managed not recognized
Offline
Do you have subversion?
sudo apt-get install subversion
Did you get the latest version from the Repository?
cd ~/Documents svn checkout svn://svn.code.sf.net/p/m30w/svn/trunk m30w-svn
OR if you already have it:
cd ~/Documents/m30w-svn svn update
And did you put in the right arguments for the file?
cd ~/Documents/m30w-svn sudo python setup.py install
Btw roijac: Comments and maybe a little txt guide on what goes on where.
Last edited by Magnie (2013-04-27 15:14:49)
Offline
Weird... It gives me this message when I run svn...
darkness3560@PenguinsFromMars:~/Documents$ svn checkout svn://svn.code.sf.net/p/m30w/svn/trunk m30w-svn
svn: E000111: Unable to connect to a repository at URL 'svn://svn.code.sf.net/p/m30w/svn/trunk'
svn: E000111: Can't connect to host 'svn.code.sf.net': Connection refused
Offline
darkness3560 wrote:
Weird... It gives me this message when I run svn...
darkness3560@PenguinsFromMars:~/Documents$ svn checkout svn://svn.code.sf.net/p/m30w/svn/trunk m30w-svn
svn: E000111: Unable to connect to a repository at URL 'svn://svn.code.sf.net/p/m30w/svn/trunk'
svn: E000111: Can't connect to host 'svn.code.sf.net': Connection refused
Hmm, try this instead:
svn checkout http://svn.code.sf.net/p/m30w/svn/trunk m30w-svn
Offline
Hey roijac, (here) is it possible to decrease the amount of code in Client.new_message by using decorators for the functions? If so, how would I do it, as I'm completely lost on how to use decorators and how they work. I want to do something similar as to what you are doing with the blocks (assign the method to a string in a dictionary so I can call it with a different name without needing the user to send a message like '/cmd_pm username message here').
Offline
Magnie wrote:
how to use decorators and how they work
A decorator is just a convenient way of applying a "decorator" function to the function you're defining.
@decorator
def some_function(x):
return x + 1
Is equivalent to
def some_function(x):
return x + 1
some_function = decorator(some_function)
Search Google for better explanation.
Offline
blob8108 wrote:
Search Google for better explanation.
Already, did, still confused.
Offline
@roijac: WHAT IS SVN??!?!
@Magnie: A decorator is just kind of a way to reduce code in functions. So if you need to call a function (func1) with another function (func2) as its only parameter, like
def func2(): #Define func2 here func1(func2)
you could just use a decorator, like
@func1 def func2(): #Define func2 here
This is commonly used with property() (tell me if you don't know what that is) so it's like
class Example: @property def class_property(): #define class_property here
Hope this helps!
Last edited by davidkt (2013-04-30 17:57:58)
Offline