How to make sine numbers in global variables?

Get help using Construct 2

» Tue Aug 28, 2012 10:16 am

Hey all, i'm wondering how to make sine numbers using global variables.

For Example

the start number is 0 and the ending number is 100, it should act like a cycle, 1,2,3,4,5,6,7,8,9,10,11,12... 100 limit is reached, then 100,99,98,97,96,95,94,93...0. Repeat 1 to 100.

Thanks!
B
87
S
21
G
18
Posts: 3,045
Reputation: 20,989

» Tue Aug 28, 2012 10:18 am

Well, if that's all you need to accomplish:

Global variable Num
Global variable Cycle

If Cycle = 0
-- If Num < 100
---- Num = Num+1
-- Else
---- Cycle = 1

Then the opposite for Cycle = 1. It's not very fancy but it gets the job done!SullyTheStrange2012-08-28 10:19:10
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

» Tue Aug 28, 2012 10:27 am

Thanks, i will try your idea!Joannesalfa2012-08-28 10:27:33
B
87
S
21
G
18
Posts: 3,045
Reputation: 20,989

» Tue Aug 28, 2012 2:41 pm

[code]Global number n = 0        // counter
Global number min = 0      // min value of the cycle
Global number max = 100    // max value of the cycle
Global number phase = 1    // phase of the cycle
+Start of Layout
-> set n to min
+Every Tick
-> set phase to (n=min) ? 1 : phase
-> set phase to (n=max) ? -1 : phase
-> set n to clamp(n+phase,min,max)[/code]Yann2012-08-28 14:43:40
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,336

» Tue Aug 28, 2012 2:50 pm

Holy wow. o_o

THAT... is the fancy version.
B
20
S
9
G
6
Posts: 607
Reputation: 6,112

» Tue Aug 28, 2012 3:33 pm

Alternatively, if you want the silky smoothness of sine, you could just set your variable to:
[code](sin(x + 270) + 1) * 49.5 + 1[/code]This will oscillate between 1 and 100. x can be any value you want, such as a variable you iterate by yourself, or you can take the game time and have a nifty one line solution.

Moderator
B
90
S
34
G
19
Posts: 1,583
Reputation: 17,315

» Tue Aug 28, 2012 7:15 pm

@Yann thanks! it's even fancier code. Make sure don't use "min" and "max" because these names are reserved for c2 expression system and @linkman2004 I don't get why sin + "x" isn't working, it appears to be invalid, did you mean we should to put an existent variable?Joannesalfa2012-08-28 19:46:08
B
87
S
21
G
18
Posts: 3,045
Reputation: 20,989

» Wed Aug 29, 2012 12:14 am

Yeah, x is simply a stand in for a variable of your choosing. For example, you could use:
[code](sin((time * 1000) + 270) + 1) * 49.5 + 1[/code]Where "time" is the actual system expression for elapsed time in seconds - multiplying this value by 1000 gets you milliseconds. Multiplying "time" by a higher number will increase the speed of oscillation while multiplying by a lower number will decrease the speed.
Moderator
B
90
S
34
G
19
Posts: 1,583
Reputation: 17,315