How do I improve these events

Get help using Construct 2

Post » Wed Dec 24, 2014 12:39 am

It doesn't look like will be a good option because I'll have hundreds of levels.

1Level2 => "1" is the epsode and "Level 2" is it's respective level.
Image
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Wed Dec 24, 2014 1:00 am

Instead of Webstorage use Dictionary for example and then use Webstorage only for saving loading the game.

I'll make my example on dictionary object.

Make a Dictionary key for episodes and one for levels.
Something like:
"Episodes" : 1
"Levels": 1

and for each new episode/level simply add a new key. For example if you start level 2 of episode 1 - add a key "1Level2" with a value = to score.

then you could do something like that

on start of layout
Is animation "Level" & Dictionary.Get("Levels") -> Set score to Dictionary.Get(Dictionary.Get("Episodes") & "Level" & Dictionary.Get("Levels"))

If your current episode is 4 and level is 3 then the last one will set score to key named "4Level3" - which holds a value of your score.
ImageImageImageImage
B
157
S
66
G
41
Posts: 2,599
Reputation: 34,825

Post » Wed Dec 24, 2014 1:06 am

@shinkan

Thanks man. I'll try it.

@shinkan

Do I need to create all the keys for all episodes and levels before and manually?And how will I create more than one Episode key without overwrite it
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Wed Dec 24, 2014 1:26 am

No, and thats the beauty of Dictionary object. You can simply do:
Dictionary: Add key "your_key_name" with value "your_key_value"

any time you want. If key with that name do not exist, new key will be created. If key with that name already exist value will be overwritten.


So you can do stuff like this:

On left mouse click -> Dictionary: Add key "click count" with value Dictionary.Get("click count")+1

On first click it will create a new key "click count" with value 1
on second click it will set key "click count" to 2
on third "click count" will set it to 3 etc.

Think of it as a global variables that can be added/set/removed on runtime any time you want :)

Oh and key values can be anything. Integers (1, 2, 34, 56..), floats (1.2, 44.34, 4.666...) or strings ("aaa", "bb bb"...)


EDIT: But if you want you can make a text file with all your keys and values already typed in and then use AJAX to load that file into a Dictionary object. This way you starts your game will all necessary data you need for your game!
ImageImageImageImage
B
157
S
66
G
41
Posts: 2,599
Reputation: 34,825

Post » Wed Dec 24, 2014 1:34 am

kossglobal wrote:And how will I create more than one Episode key without overwrite it


You probably always start on episode one. So you can make a counter to keep count of episodes (1,2,3,4...) - this can be a dictionary key as well.
Then on start of each new episode you can add a new key: Add key "Episode" & counter - in this case value of the key is not important, You only need a key to exist.

and then if you finish last level of current episode simply add 1 to counter.
This will make a new key every time you start new episode automatically - "Episode1" key, "Episode2" key etc.

If you want later to check if current episode was started/finished or whatever you can simply use
Dictionary: Has key "Episode1" -> do your events.
ImageImageImageImage
B
157
S
66
G
41
Posts: 2,599
Reputation: 34,825

Post » Wed Dec 24, 2014 1:42 am

shinkan wrote: you can simply use
Dictionary: Has key "Episode1" -> do your events.

Dictionary: Has key "Episode2" -> do your events.
Dictionary: Has key "Episode3" -> do your events.
Dictionary: Has key "Episode4" -> do your events....
....and you have 100 events again ;)
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Wed Dec 24, 2014 1:46 am

nope :) read my first post again ;)

Dictionary: Has key "Episode" & counter -> do your events.
And if you run it through a loop you will only have one event to rule them all ;)
ImageImageImageImage
B
157
S
66
G
41
Posts: 2,599
Reputation: 34,825

Post » Wed Dec 24, 2014 1:56 am

Ok.. I believe you...but .. i do not understand (see my signature :D )
how you check "Episode" ..if E=1 do..If E=2 do..... ?

Edit: @kossglobal you dont need webstorage for all levels just for last.. webstorage key "last level" & global variable" Last level"....if player "win" on level 1 ..set "last leve" tol 1..
Last edited by korbaach on Wed Dec 24, 2014 2:07 am, edited 2 times in total.
Image
B
65
S
23
G
7
Posts: 1,505
Reputation: 10,896

Post » Wed Dec 24, 2014 2:03 am

@shinkan

I'm sorry but I'm too stupid to understand it =´[

I don't know dictionary very well.

I'll try to explain where i'm stuck. For example, when the player accomplish the level 2 of the episode 1 I'll save it with webstoreage => "Set Local Key LayoutName (which is 1Level2) to ScoreTemp (which is a global variable that holds scores until it get saved)
Ok, then I get lost. When do I need to add keys to episode and levels?I mean, the value will be the string episode and the key will be my "value"?
and...Sorry I would add more questions but i'm too lost to even know what is it LOL
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Wed Dec 24, 2014 2:45 am

@kossglobal

let's make it simpler. Imagine you have 3 variables:

1. Number variable [episode] = 1 - this will keep track of current episode you are playing
2. Number variable [level] = 1 - this will keep track of current level you are playing
3. Number variable [score] = 0 - to keep track of current player score


When player finish any level you make an event:
Dictionary: Add key "[episode] & "level" & [level]" with value [score]


So when player finish level 2 of the episode 1 and his score is 1234 it will add a key [ "1level2": 1234 ]
when he finish level 5 of episode 3 with score 5432 it will add a key [ "3level5": 5432 ]

so key name is made of a combination of: variable [episode] a string "level" and a variable [level] - which gives for example "3level1". And value of that key will be a variable [score].

@korbaach

if you know how many levels and episodes you have you can make a simple loops

For example there is 5 episodes with 4 levels each and you already have finished all 4 levels of episode 1 and 2 levels of episode 2. Each level have it's own score.
"1level1": 1234,
"1level2": 567,
"1level3": 432,
"1level4": 674,
"2level1": 33,
"2level2": 8,

Now on start of the layout you want to create and set text to score for each level:

+On start of layout
++For "ep" from 0 to 5
++For "lvl" from 0 to 4
++ Dictionary: Has key [ loopindex("ep") & "level" & loopindex("lvl")
-> Create Text on layer "zzz" at (X,Y)
- > Set text to Dictionary.Get(loopindex("ep") & "level" & loopindex("lvl"))

Hope I make any sens, it's almost 4 AM over here ^^


EDIT: and yes you only need Webstorage if you are actually want to save/load current game state. With Dictionary it's super easy. You only need one event Webstorage: Set local key "key name" to Dictionary.AsJSON. This will save entire dictionary object as a one webstorage key.
ImageImageImageImage
B
157
S
66
G
41
Posts: 2,599
Reputation: 34,825

Next

Return to How do I....?

Who is online

Users browsing this forum: evillair, plinkie, YoHoho and 11 guests