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

Get help using Construct 2

Post » Fri Oct 16, 2015 10:14 am

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.
B
14
S
5
Posts: 37
Reputation: 1,026

Post » Fri Oct 16, 2015 4:40 pm

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?
Bushy Ball\Boatman Bill\Sticky Web\Snake

Image ImageImageImage

During the gold rush it was a good time to be in the pick and shovel business
B
47
S
14
Posts: 253
Reputation: 5,389

Post » Sun Oct 18, 2015 7:39 pm

@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?
B
14
S
5
Posts: 37
Reputation: 1,026

Post » Sun Oct 18, 2015 8:24 pm

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:

Image

After I cancel it, it actually gives me the values I was looking for...but what does that error mean?
B
14
S
5
Posts: 37
Reputation: 1,026

Post » Mon Oct 19, 2015 5:28 am

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.
B
94
S
33
G
114
Posts: 5,360
Reputation: 73,781

Post » Mon Oct 19, 2015 6:54 am

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 :)
B
14
S
5
Posts: 37
Reputation: 1,026

Post » Mon Oct 19, 2015 9:42 am

@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.
B
14
S
5
Posts: 37
Reputation: 1,026

Post » Mon Oct 19, 2015 5:41 pm

@actuallybrown
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.
B
94
S
33
G
114
Posts: 5,360
Reputation: 73,781


Return to How do I....?

Who is online

Users browsing this forum: Christmas, dop2000 and 16 guests