From python, trying to grasp dictionaries

Get help using Construct 2

Post » Mon May 20, 2013 12:29 am

EDIT: I am having the most trouble with For loops. In Python I use them by defining a 'helper' parameter and using it to run through lists and dicts. I can't seem to do this Construct 2. EX:

list = [1,2,3]
for x in list:
    print "Hello"

Is there a way to use a for loop in this manner in Construct 2?

Hi Community! I just plunged into Construct 2 and I'm trying to draw some kind of similarity to what I've been doing in Python recently. I've found dictionaries and a little bit of information on how to manipulate them but I can't see how to perform some of the things I did in python. Example code:

mbeerlist = {}       

Stout = Beer('Stout', 'Beer', 10, 95, 70, 40, 40)
Porter = Beer('Porter', 'Beer', 10, 80, 50, 50, 30)
IPA = Beer('IPA', 'Beer', 100, 30, 70, 90, 50)

brew1 = Beer('unknown', 'unknown', 10, 50, 80, 30, 50)

def rate_beer(brew, mbrewlist, amt, inv):
        global mbeerlist
        bestbeer = None
        bestrate = None
        for beer in mbeerlist:
            rate = 0
            rate -= abs( mbeerlist)['Color'] - brew.color )
            rate -= abs( mbeerlist)['Profile'] - brew.profile )
            rate -= abs( mbeerlist)['Bitterness'] - brew.bitterness )
            rate -= abs( mbeerlist)['Carbonation'] - brew.carbonation )
            if (rate > bestrate) or (rate == None):
               bestrate = rate
               bestbeer = beer
               brew.type = mbeerlist)
        print 'Congratulations! You\'ve brewed a ' + str(bestbeer) + "!"
        print 'Your beer rating is: ' +str(100+int(bestrate)) + "% !" = raw_input('Pick a name for your brew! ')            
        print "It is now in your Beer Inventory!"

In this, a loop compares a player made beer (a dictionary with 4 values used to define it) and compare it to a list of all the types of beers, eventually picking the beer type it was closest to. In a simplified example, it would conclude: Player beer is 30, Porter is 40, IPA is 50. Player made a Porter!

So... Is something like this feasible in Construct 2? I've started it with dictionaries, then arrays, then sprites, but I just can't seem to get a feel for how to transition this idea to C2. BTW I love the program otherwise. It really appears to be indie game on easy mode. Thanks for any help in advance. amishstripclub2013-05-20 10:04:40
Posts: 31
Reputation: 598

Post » Mon May 20, 2013 8:08 pm

Here's a little example of using loops and dictionaries. See if it helps:

Posts: 1,520
Reputation: 25,650

Post » Mon May 20, 2013 9:18 pm

Awesome work. I'm working through how it operates right now but it definitely demonstrates something along the lines of what I had going in python. Thanks!
Posts: 31
Reputation: 598

Return to How do I....?

Who is online

Users browsing this forum: Lancifer, nahima, Phacanu and 27 guests