2015-08-06 20:32:52 (edited by Kyleman123 2015-08-20 03:43:40)

hello all,

hope this finds you well. monopoly development for the most part is going very smoothly i've learned a lot about a lot of things throughout the whole process. but i came across some interesting behavior and wanted to get it out here and see if anyone had anything to say about it. i've developed what is called a state programming  pattern or a state machine in my game. for those of you that don't know what that is: everything in the game is a screen and the game cycles through the screens as needed. i'm holding the screens in the game stack. only the top screen (list[-1]) gets the focus at one point. i don't really see any need for keyboard import to trickle down the stack to other screens at the moment but i'm using this because its a good model for games and i can easily add to my understanding of this if i create something more complex in the future. all that beeing said, my function for switching screens is buggy. adding screens is working amazingly well. the issue comes in when i need to remove more than one screen off the stack at a time. this isn't copied code for code below, but i hope you get the general gist and can help me flush out some better practices out of this. the underlying engine for how the game runs needs to be super solid and its not at the moment.

each screen returns a string which the engine uses to look up the next screen in a dictionary.

def screen-switcher(self):
    self.next_screen = self.screen_dict[self.next_screen]
    #looks up screen in dict
    if self.next_screen in self.stack:
        #seeing if screen obj is already in the stack
        for screen in reversed(self.stack):
            if self.stack.index(self.next_screen) != -1:
                 try:
                    app.remove_from_stack(screen)
                    #i want it to remove screens until the specified screen is on top
                except ValueError:
                    app.add_to_stack(screen)
    else:
        app.add_to_stack(self.next_screen)
        #if screen isn't in the stack already, it just gets added

this seems to be mostly doing what i want it to do. but it doesn't seem to be catching the value error that the screen was removed. any help making this more solid would be appreciated.

I don’t believe in fighting unnecessarily.  But if something is worth fighting for, then its always a fight worth winning.
check me out on Twitter and on GitHub

2015-08-19 06:07:15

wait what language is that?

If you have issues with Scramble, please contact support at the link below. I check here at least once a day, so this is the best avenue for submitting your issues and bug reports.
https://stevend.net/scramble/support

2015-08-19 06:56:32

It looks like Python to me.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2015-08-19 16:07:11

yes python. i believe i fixed the issues i was having, but if anyone wants to suggest any good practices go ahead.

I don’t believe in fighting unnecessarily.  But if something is worth fighting for, then its always a fight worth winning.
check me out on Twitter and on GitHub

2015-08-19 22:06:30

I get the gist of what your doing, but its difficult to tell why your doing it without knowing more about the rest of the code. Does this function add and remove "screens" from dictionaries? Or does it load/remove it from an "app" stack? What API are you using?

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2015-08-19 22:58:45 (edited by dhruv 2015-08-19 22:59:35)

This line makes no sense:

    self.next_screen = self.screen_dict[self.next_screen]

Are you...I don't know. You haven't defined self.next_screen yet, so you can't look it up in the dictionary. It's really weird. Were you trying to do this?

    self.next_screen = self.screen_dict["self.next_screen"]

Also it would be cool if you posted your code blocks in a left bracket code right bracket...left bracket / code right bracket tags. This way the indentation remains fine.

This is not a signature.

2015-08-19 23:44:50

He didn't post all the code, just a snipet. So I'm guessing that self.next_screen holds a string thats defined in the other parts of the code.

-BrushTone v1.3.3: Accessible Paint Tool
-AudiMesh3D v1.0.0: Accessible 3D Model Viewer

2015-08-20 03:47:30 (edited by Kyleman123 2015-08-20 03:48:21)

okay code edited with the code blocks.
yes self.next_screen is the variable that holds the string that was returned from the current_screen. it is used to find the corresponding screen_object in the dictionary. i'll have to pull up my code and see what i did to make this work. because it is working at the moment.

I don’t believe in fighting unnecessarily.  But if something is worth fighting for, then its always a fight worth winning.
check me out on Twitter and on GitHub