Integer problem

0 favourites
  • 9 posts
  • I have been wrecking my brain with this problem for three days now, so I think I give in and ask for help.

    In my game, you play as a sheep with horns that grow when you level up. Wrecking stones and things with your horns make them break a bit, regressing a tick. I can't get the latter part to work.

    Clearly the problem is that the horn growth is tied to the level. So even when I decrease the horn growth variable, it grows back up in the second because of the level. I'm just too dumb to see a way around it.

    Here's the capx link that illustrates the problem.

    https://mega.nz/#!DVdwDAAA!ncdLV3k8pi1VFrQEmC-lJpLodfIO6lju392kQ8dsHhs

    Just click to try to break off the horn.

  • Well, it's right there in event #6. This event is executed on every tick, so horns is constantly getting reset to (level-1)

    You should probably move this action to "On start of layout" event.

  • Okay, I'm not really following you.

    If I put it to start on layout, the horn stops growing altogether. That event is there that keeps the horn growing, if you run it once it only gets run once.

    Of course that is the problem. I need a way around it.

  • Ok, then remove event #6, and add an action "Add 1 to Horns" to event #1.

    This way every time the level is increased, Horns will also get increased by 1.

  • That works on the simulation capx, but not in the real game. In the real game the level is counted every tick against the score which is updated every tick based on how far the player is traveled.

    Since the level is updated every tick, so the horns are also updated every tick, causing them to grow full lenght in the first level. I'm starting to think that instead of tying it to the level, I could just spawn invisible barrier every level as checkpoints that'd grow the horns when passed.

    Unless you have a better idea?

  • You should only add 1 to horns when you add 1 to level. It's that simple.

    If your level variable is increasing correctly, then put "Add 1 to horns" in the same event.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • But the levels aren't added, they're calculated every tick. Here's how I have it done. Scores, levels and spawners. They're all under 'every tick'.

  • Ok... In this case it's probably easier to create a variable called HornsLost. Every time you break a horn, add 1 to HornsLost. On every tick set Horns to (Level-HornsLost)

  • Okay, that works! Thanks!

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