![]() |
Sleep/Timer help
I am trying to have an image I have made, rotate slightly, then rotate back.
This is the only way I know how to do it. I am hoping someone can teach me the proper use of the 'sleep' function or perhaps advice me another way to write it. This does work, but I don't like how It's so long. and too many OnThis functions. btw, the 'OnRot' stands for 'on rotation.' Quote:
|
I'm not sure if it matters but i belive your missnig a value in the scheduleEvent.. I'm not sure, i haven't really worked with schedulevents but wouldn't it be something like
PHP Code:
|
Just set the spin value to 1 or something, it'll automatically rotate the image for you.
Your code is also very redundant. PHP Code:
|
Quote:
|
I would probably do it kind of like this:
PHP Code:
|
@Tigairius, do you mind explaining a little.
1. What does "i" mean in the this.i? 2. also, what is pi? |
Quote:
First, pi is a number- it's a constant that is the ratio of a circle's circumference to its diameter. It is equal to approximately 3.14159 (although it's irrational so it actually goes on "forever"). Pi is used closely in the sine function ( aka: sin(x) ). Sine is a repeating wave across the x axis. So, as X increases, it will yield a number between -1 and 1 (as seen on the graph below). Its wave-like behavior means that as you increase X, it will fluctuate between positive and negative, allowing for us to use it in that fashion to achieve the desired affect of "rotating forward, then back again". http://i.imgur.com/3bmHA.png For more information on sine, pi, cosine, or other trigonometric functions, check wikipedia. http://en.wikipedia.org/wiki/Sine http://en.wikipedia.org/wiki/Pi |
OOh ok. Well I have one more question, is there necessarily anything wrong with the way I wrote it? (using multiple scheduleEvents)
Or is it just not reccomended to write it like that.? |
Quote:
|
Is repetitivness bad?
|
Quote:
PHP Code:
PHP Code:
|
Quote:
He means it's repetitive because you have a lot of functions that do, essentially, the exact same thing, when you could've reduced it to one or two functions to complete the task. One way to have done it without the sine function that is much closer to the way you originally wrote it, is something like this: PHP Code:
You could even go a step further, and write it somehow like this: PHP Code:
|
Quote:
I get up to the question mark which then confuses me... I don't know how much he knows about programming or math, but some things that may be common sense to some programmers may not be as such to those just getting into the scene. That and we all have certain skills inside the language we are good at and others we've never bothered to touch. I think you mean to say easier to read all at once, rather than easier to comprehend? :x It takes the system more time to read 20 lines when it can read 4... Anyway, positive reputing your post explaining sign to him, I believe most people would not take the time to do something like that. |
Quote:
Here it is written in English: RESULT = BOOLEAN ? DO THIS : OTHERWISE DO THIS; A boolean is simply a statement or value that is either true or false. Now I'll show you an example of converting an if-else statement into ternary. PHP Code:
findImg(3).rotation = this.counter >= 4 ? 3 : -3; The red text is the BOOLEAN. If it's true, it will return/execute whatever is in blue, if it's false, it'll return/execute purple. |
| All times are GMT +2. The time now is 05:18 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.