How do I make a Sine Period key value-sensitive?

0 favourites
  • 8 posts
From the Asset Store
Random Maze Generator with Door & Key System - tutorial capx
  • I'm making a simulation RPG, where the user levels up different attributes of a character throughout the game. In it, there's a mini-game in which a meter oscillates back and forth, and the user has to stop it on a particular area to get the most points.

    What I want to do is make this meter's oscillation speed be inverse to their attribute point rating (so like, 'attention level 20/100' would make the meter fast, while 'attention level 80/100' would make the meter slow, etc.).

    I'm trying to just set the actual Sine wave Period of my meter to a Dictionary key value, divided by a number. I.E.:

    • Dictionary.Get("attention") / 50

    But the expression is not working mathematically. It just calls the value previously stored for 'attention', but doesn't do the division math.

    Thoughts? Thanks in advance.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • start of layout>dictionary add key "attention" value (your value here)

    >dictionary set key "attention" value (your value here)

    Every tick> (your sprite here) set sine period to Dictionary.Get("attention")/50

    This will work, maybe you did not add the key, before setting the value?

  • sizcoz, I declare/define the key in another layout, and when I'm running the test I start with that layout in order to properly run through the workflow.

    Am I not supposed to have spaces around the operators (for divide, add, subtract, etc.)? In the C2 manual they put spaces around the operators when they do operations like this. [Ex: (Player1.X + Player2.X) / 2]

    Also, is adding a key and setting a key, for the purposes of what I'm trying to do, not the same thing?

  • What I ended up doing was this:

    System > Every Tick > [sprite name] > Set Sine Period to Dictionary.Get("attention")

    ____________________ > [sprite name] > Set Sine Period to [sprite name].Sine.Period / 50

    But that seems to give me an error:

    After I cancel it, it actually gives me the values I was looking for...but what does that error mean?

  • It looks like a bug which would be good to report.

    You can probably work around it by using :

    float(Dictionary.Get("attention")) instead of Dictionary.Get("attention"). I'm guessing the value of "attention" isn't a number, or at least isn't right away.

  • The value was stored as a number, and when I debug the dictionary, it was being returned as a number (integer), so I'm not sure what the problem was. I'll try that though, and I guess add the bug >> at some point

  • R0J0hound, actually, now that I've converted all of my Dictionary values to Instance Variables, and cleaned up some conversions, I think you were right in that I may have been pulling a text value that just happened to be storing a number, but as string.

  • depending on your game logic, it may have been asking for the value from the dictionary before it was set. That would make it's value NaN.

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