|
From: skn154 on 14 Apr 2008 16:44 Hello everyone, I'm creating a dressup game for kids, which will have a score system. There are 3 items of clothing worth 10, 15 and 20 points. On one page they can select the garments. I've created a global variable called gScore and have set it to 0 in startmovie. On the sprite of each garment of clothing I've used the following code gscore = gscore + 20 Thing is, each time you click, it adds 20 to the total. so if you click twice, the total will be 40. I only want it to be add to the total once and not each time a user clicks. If the user click on another garment of clothing; for example worth 15 points, that will be add to 40. I also don't want this to happen as the user can only select one garment of clothing. So basically the user can score a maximum of 20 points, because they can only select 1 as this point. If I select the garment worth 15 points, and change my mind and select the garment worth 20 points, how can I recognise this and deduct 15 point from the total and add 20? Its sounds confusing... Thanks everyone
From: Mike Blaustein on 14 Apr 2008 17:16 Instead of (or in addition to) your gScore global, I would make another global for each clothing type. I have no idea how your game is structured, but let's say you have Shirts, Pants, and Shoes. Each time you click on a shirt, it will put in that shirt's value and remove the previously saved shirt value while leaving the rest intact. global gScore on startMovie gScore=[:] gScore[#shirts]=0 gScore[#pants]=0 gScore[#shoes]=0 end That will instantiate your list when the movie starts. Then you would put this on each clickable clothing item: global gScore property pGarmentType property pValue on mouseUp me gScore[symbol(pGarmentType)]=pValue end on getPropertyDescriptionList me p=[:] p[#pGarmentType]=[#format:#string,#comment:"Which garment type?",#default:"shirts",#range:["shirts","pants","shoes"]] p[#pValue]=[#format:#integer,#comment:"How much is this one worth?",#default:0] return p end (watch out for inadvertent line breaks - that should be exactly 14 lines of code) That will let you define which garment type the item is, and how much it is worth. Feel free to set the different garment types to be appropriate for your use... Anyway, on your score counter, you would simply add the values together like this: global gScore on enterFrame me theScore=gScore[#shirts]+gScore[#pants]+gScore[#shoes] sprite(me.spriteNum).member.text=string(theScore) end
From: skn154 on 14 Apr 2008 18:32 Thanks Mike, I'm having trouble understanding the code that goes into the clickable item of clothing. I am also getting an error message gScore[symbol(pGarmentType)]=pValue - Index out of range There are three outfits to chose from. I've named them : Outfit1, Outfit2, Outfit3 Outfit1 = 10 points Outfit2 = 15 points Outfit3 = 20 points how does the following code work? p[#pGarmentType]=[#format:#string,#comment:"Which garment type?",#default:"shirts",#range:["shirts","pants","shoes"]] p[#pValue]=[#format:#integer,#comment:"How much is this one worth?",#default:0] I'm not familiar with properties Thanks again so much for your help, hopefully I'll learn something new! Many Thanks
From: Mike Blaustein on 15 Apr 2008 06:27 That stuff is part of the "getPropertyDescriptionList" handler. Basically, when you put the script onto a sprite, it will present you with a few options. And the options you choose in that menu will define how the script works. In this case, there are 2 questions it will ask. One is garment type and the other is value. You will get the value out of range if you are trying to set the score of a garment type that does not exist. In startMovie, we set three different garment types, Shirts, Pants, and Shoes. Each clickable clothing item will be one of those three types. Which one it is will be defined by your selection in the GPDL. If it is easier to understand without using properties, the point of the situation is that we have 3 globals defining the score. Not just the one gScore. I separated them and put them into a single property list. You could use 3 globals like gShirtScore, gPantsScore, gShoesScore. Then each time you click a Show item, it sets the value of gShoeScore. And the text sprite that shows the actual score simply adds the three together.
|
Pages: 1 Prev: How to save XML file in UTF-8 code page Next: Problem with rotating dynamic sprites |