Best way to reset global variables of specific Event Sheet?

Get help using Construct 2

Post » Sat Aug 08, 2015 9:19 pm

Hello C2 developers! ^^

After integrating many casual games in one CAPX project (a WarioWare Inc. similar game), I'm finding into some problems related to global variables. Each CAPX is now a layout with their respective EventSheet, so I created a intermediary Layout + EventSheet who, besides showing the lives of the player and the total score, also contains all the global variables and events of random generation of casual games.

Well, it happens that whenever I revisit a previously played game, bugs appears, most likely due to global variables of that game still contain values ​​of the previous move. I tried to apply the command "Reset global variables to default", but its effect was for the entire game and not just for the EventSheet a game. :(

Does anyone have a suggestion on how to reset the global variables of each EventSheet game after its completion, without restarting the variables of the entire project?

PS.: Each Event Sheet game contains three variables whose values are taken to the intermediate Sheet Event: Victory condition, loss of condition and partial score.

Thank you in advance the attention and collaboration of all.
Last edited by lukezero on Sun Aug 09, 2015 2:06 pm, edited 1 time in total.
B
39
S
9
G
3
Posts: 261
Reputation: 4,363

Post » Sat Aug 08, 2015 9:29 pm

By their very nature, anything to do with Global Variables will not take their location on an event sheet into account because they are accessible throughout the project. You'll have to set just the ones you want to their original values manually.
Last edited by Ahr Ech on Sat Aug 08, 2015 11:05 pm, edited 1 time in total.
B
35
S
9
G
4
Posts: 201
Reputation: 5,172

Post » Sat Aug 08, 2015 10:05 pm

@Ahr Ech, so the best solution is create a Function to reset each global variable to its original values in case of victory and loss conditions?
B
39
S
9
G
3
Posts: 261
Reputation: 4,363

Post » Sun Aug 09, 2015 1:56 am

based on what you said... in your system you have created you have 10 games in 1 bigger game that uses some Global variables and resets them ... thats because all Global variables you set for each game have the same name... if you want them to reset for each individual game..you will have to redo all you games even sheets...

the people above this post already gave a spot on response... but then im guessing and hoping you want more info how to make it work again i guess? (its not that i mind to share info... its just i already typed the info you wold need before i typed this message here above... and its a waste of 700 words if you know what i mean..673 actually but who is counting..... hah....... 3515 characters...nevermind a bad joke....... wold look bad .... :lol: )

adding new global variables to take the place of the original one... so lets say your global variable is Score

now if you have score for all when u reset the score in one of the game it will automatically reset in all of them .. cause its global... i hope it makes sense... if i dident lost you on the way here... then lets continue..

now in order to avoid that the simplest way is to set for each game... different Global variables... such as Example of game with its own global variable : MarioPacking > Global variable Score ..... Game nr N .... MarioPackingGuns > GlobalVariable Score2 ... and so on..

that is the easy way...
now if you already went and done some SQL databases or worked with the score and saved it in some Arrays or Tables ... you can add a Global Variable ( number) and set it for each game to a number to keep it simple lets start pointing them from 1 incremental to last game in ur list..

now when u are saving the score.. on each start of a game ...set the new variable to its number ( game 1 variable value 1 and so on..)

now once you have that the proper saving wold be to check the number for the game... so if you are in game 1 and variable value is 1 save game Global Variable in Table 1

if game over and in game 1 and variable value is 1 then erase Global Variable from table 1

and so on... this way ... you work with 1 global variable in all your games... but you need an Array or some SQL database .. to create Tables in... if you know how to make it work with C2 ...if you dont know how to work with it ... or it is not necessarily then forget the bellow text

but if you did used it... and dont know how to setup the Tables... sadly i cant cover that part here... but you can find a bunch of tutorials... and also there is a new plugin called Photon.Cloud i think or just search for Photon...basically it does the SQL databases and the score tables for you already ... or not quite but lets u connect it to your C2 game easier then trough Ajax... you just need to add tables with names... which is very visual and easy to understand similar to Construct2 event-sheet then you take a API key and some hidden encrypted code.. you have for each database add their plugin in your project.. and the secret keys in its preferences and your good to go.. you wold need just to call ur tables for updates and set their values.. they even have a example capx.. its pretty decent... but i think you will be better with the easy way i guess... if you dont want to go on online databases to just save some numbers... which will be kinda hard for future maintenance .. since will be more costly then local saving..


hope i was in the range of your discussion ... and this is still an issue to respond to... if its already solved please Add [Solved] in title of topic.. have a great day and good luck with your project :)
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » Sun Aug 09, 2015 11:43 am

WOW! Thanks for your great explanation, @gamecorpstudio! :D

It isn't every day that you see so much attention and cooperation!

Well, I certainly will use a database for storing local data, for my own game score and High Score. Your tips were of great value in this too.

My current problem was more focused on the issue of global variables and how to restart them between one game and another, but that I believe could solve.

I'm testing some stuff now and I'll give feedback through the day.

Again, thank you for everything! ^^
B
39
S
9
G
3
Posts: 261
Reputation: 4,363

Post » Sun Aug 09, 2015 11:47 am

@gamecorpstudio Just an observation: I'm using global variables instead of tables and matrices to raffle the mini-games, as the random generation is temporary and disposable. That is, the only variable that should be stored in the game is the High Score, so I'm opting for Local Storage.

What do you think? ^^
B
39
S
9
G
3
Posts: 261
Reputation: 4,363

Post » Sun Aug 09, 2015 2:05 pm

lukezero wrote:@gamecorpstudio Just an observation: I'm using global variables instead of tables and matrices to raffle the mini-games, as the random generation is temporary and disposable. That is, the only variable that should be stored in the game is the High Score, so I'm opting for Local Storage.

What do you think? ^^


the local storage is as good as you want it to be.

if you want in future to change to a online storage platform, then youl have to tweak a lot of things, which will become tedious at some point, but if you take some extra time now while your in development and push it into the online platform will make your life easier in future if you have a cheap way for maintenance... there are a few and u could do it on a free hosting service also... but that will involve ajax and php scripting and its kinda a head ache

im glad you find the info i posted helpful, im happy to help

P.S remember going on online platform is easier later, but kinda frustrating, if you never worked with this kinda features.. since you have to learn trough documentations and tutorials... but its possible... trial and error that will make you uncover new skills you need in this domain... Cheers :D
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » Sun Aug 09, 2015 6:33 pm

Sure, @gamecorpstudio dude! The only online function of the game will be a ranking with the highest scores of the players. The game will initially be released only in the Google Play platform.

Well, now I'm having trouble using global variables. All mini-games work well at first, but when revisited, are having problems. I created a function for each mini-game that resets the necessary global variables to their original values and these functions are called at the Start of Layout. However, apparently this isn't working. :(
B
39
S
9
G
3
Posts: 261
Reputation: 4,363

Post » Mon Aug 10, 2015 1:12 pm

can you show a event sheet screenshot of the function ur using?

im pretty sure you forgot to change the names of the variable... in which case there is no need for functions really... you'd be better doing it trough a boolean or just a simple variable local or not..


... good morning BTW just waked up... coffee time here :P well not really 4pm lol... but this is my hr when i wake up so.... ... brb
B
78
S
23
G
69
Posts: 1,353
Reputation: 44,005

Post » Mon Aug 10, 2015 1:26 pm

Good morning, @gamecorpstudio. :)

I didn't understand your suggestions, man. :(

This problem is only happening when a mini game is revisited, and fortunately, only three of them.

Now I'm testing to reset the boolean variables too and seems to be having some effect. :)

I also realized that one or other strange behavior is situated in groups that are turned on and off through the mini-game. I'm looking for alternatives for that too.

If anyone has suggestions, I will be eternally grateful. ^^
B
39
S
9
G
3
Posts: 261
Reputation: 4,363

Next

Return to How do I....?

Who is online

Users browsing this forum: Cubeeo and 19 guests