Help me with Global Variable & Group

0 favourites
  • 10 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I want to have difficulty modes like Easy, Medium and Hard. Basically what I do is make the enemy tough.

    So, for that, I have different groups, Easy, Medium and Hard Group, For each, I have programmed the tough levels.

    So what I have done?

    I have created a Global Variable and made it to 0. When the user clicks the Easy Mode (From Main Menu Layout), then the Global Variable would be 1. On Start of the game layout, If the Global variable is 1, then the "EasyModeGroup" would be activated.

    But sadly it won't work, I must have doing it wrongly, Please guide me through.

  • I also tried it with Local Storage, but still no luck.

  • The groups are disabled, that means they are entirely ignored. Right click on the groups, select edit and remove the check from "active on start" instead.

  • The groups are disabled, that means they are entirely ignored. Right click on the groups, select edit and remove the check from "active on start" instead.

    Man, thank you very much.

  • WackyToaster One issue, Please help.

    In my platformer, I have a total of 8 worlds, When User open the game for the first time and click new game, there would be three option to select Easy, Medium and Hard.

    If a user played "Normal Mode" and go to WORLD 1, mid of the WORLD there is a checkpoint (using Save & Load) when the user collided with the checkpoint and then if he died, the game would continue from that checkpoint. When the user clicks the continue after died, the game would be started from that location and along with "Normal Mode". (Which is perfectly fine)

    But the issue is when the user closes the game (in the phone) and started to play again and click the continue button, the game start from the previous checkpoint but now there is no "Normal Mode".

    So basically system unable to save the Global Variable of the Normal Mode.

    I also tired with Local Storage completely without using the global variable, (please ref: previously attached image) but unable to make it work.

  • Just a suggestion...

    If the only change between modes is the enemies' life and maxlife, I would drop the groups entirely.

    Just creat e lifeMultiplier variable and a difficultyLevel variable.

    When player chooses difficulty set the difficultyLevel to the corresponding valeue (0: easy, 1:normal, 2:hard). And when you create enemies just check the difficultyLevel and set their life and maxLife to the corresponding value.

    Ex.

    Enemy "On Create"{
    Enemy Set maxLife = (difficultyLevel = 0) ? 50 : (difficultyLevel = 1) ? 100 : 200;
    Enemy Set life = maxLife;
    }
    

    You'd have far less code in your project!

    Remember to save the chosen difficultyLevel to the local storage if you don't want players ahving to choose it every time they start the game.

    Hope this helps...

    Cheers!

  • Just a suggestion...

    If the only change between modes is the enemies' life and maxlife, I would drop the groups entirely.

    Just creat e lifeMultiplier variable and a difficultyLevel variable.

    When player chooses difficulty set the difficultyLevel to the corresponding valeue (0: easy, 1:normal, 2:hard). And when you create enemies just check the difficultyLevel and set their life and maxLife to the corresponding value.

    Ex.

    > Enemy "On Create"{
    Enemy Set maxLife = (difficultyLevel = 0) ? 50 : (difficultyLevel = 1) ? 100 : 200;
    Enemy Set life = maxLife;
    }
    

    You'd have far less code in your project!

    Remember to save the chosen difficultyLevel to the local storage if you don't want players ahving to choose it every time they start the game.

    Hope this helps...

    Cheers!

    Thanks for your input, actually it was a demo I need something more than just enemy life. If the user restarts the game there where the problems lie. And thanks for your suggestion I'll definitely try to implement it in other way.

  • Please help me.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • In that case I would use a 3D array where X is the difficulty level, Y is the Enemy ID and Z is the Attribute.

    Example (in JSON format):

    {"c2array":true,"size":[3,2,3],"data":[
     [
     [50,150,10], [75,100,25]
     ],
     [
     [100,250,25],[150,150,50]
     ],
     [
     [200,350,50],[300,200,100]
     ]
    ]}
    

    Each line is a difficulty level (Easy(line 3), Normal(line 6) and Hard(line 9)).

    Each block in a line ([50,150,10] for instance) is an enemy. In this list there are 2 enemies.

    And each item in the block is an attributes (Let's say Life, Speed and Damage for this example)

    First enemy is weaker and causes less damage, but is faster than the second. In Easy difficulty, for instance Enemy 1 has 50 life, 150 speed and 10 damage, while Enemy 2 has 75 life, 100 speed and 25 damage.

    This way, when you create an enemy just access the values in the array for the corresponding difficulty and enemy using array.At(difficulty, enemyId, attributeId).

    Let's say the difficulty is HARD and you are spawning a Enemy of the second type. Its life would be enemiesArray.At(2, 1, 0), its speed would be enemiesArray.At(2, 1, 1) and its damage would be enemiesArray.At(2, 1, 2).

    Check this example. It will ask for the difficulty the first time and afterwards it would just use the one saved. It will also list the picked difficulty and the attributes for each enemy at each difficulty.

  • In that case I would use a 3D array where X is the difficulty level, Y is the Enemy ID and Z is the Attribute.

    Example (in JSON format):

    > {"c2array":true,"size":[3,2,3],"data":[
    > [
    > [50,150,10], [75,100,25]
    ],
    [
    > [100,250,25],[150,150,50]
    ],
    [
    > [200,350,50],[300,200,100]
    ]
    ]}
    

    Each line is a difficulty level (Easy(line 3), Normal(line 6) and Hard(line 9)).

    Each block in a line ([50,150,10] for instance) is an enemy. In this list there are 2 enemies.

    And each item in the block is an attributes (Let's say Life, Speed and Damage for this example)

    First enemy is weaker and causes less damage, but is faster than the second. In Easy difficulty, for instance Enemy 1 has 50 life, 150 speed and 10 damage, while Enemy 2 has 75 life, 100 speed and 25 damage.

    This way, when you create an enemy just access the values in the array for the corresponding difficulty and enemy using array.At(difficulty, enemyId, attributeId).

    Let's say the difficulty is HARD and you are spawning a Enemy of the second type. Its life would be enemiesArray.At(2, 1, 0), its speed would be enemiesArray.At(2, 1, 1) and its damage would be enemiesArray.At(2, 1, 2).

    Check this example. It will ask for the difficulty the first time and afterwards it would just use the one saved. It will also list the picked difficulty and the attributes for each enemy at each difficulty.

    Thank you very much for this detailed post and for the capx, really appreciated. Let's see how far I pull from this logic as this logic is kind of pro for me.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)