Peachpit: Working with C++ Operators and Control Structures:: This mini guide covers exactly what you need to know about C++ operators (special functions that perform arithmetic and boolean operations) and control http://www.peachpit.com/store/product.aspx?isbn=0321481143HOME | Im currently working on a game for flash with some very complex movement.
What I need to do is to change the direction the player moves when a certain key is pressed, making it the exact opposite of the direction the player would normally.
Example :
up arrow key moves the player forward, when the spacebar is hit the up arrow moves the player backwards.
So this is the code im using to move the player MC :
if (Key.isDown(Key.UP) ) {
if (angle == 360) {
this._y -=10;
}
}
so what needs to happen is that this._y -=10; needs to become this._y +=10;. So i thought 'ill just use a variable!', first problem was that the decision to change the operator comes from a different timeline, solved that with a _global variable, but when I entered : PHP: Error Control Operators - Manual:: Jun 26, 2008 PHP supports one error control operator: the at sign (@). Currently the "@" error-control operator prefix will even disable error http://www.phpbuilder.com/manual/en/language.operators.errorcontrol.phpHOME |
this._y variable_name=10;
it didnt like it so I tried :
this._y [variable_name]=10;
that seemed ok, but when I tested the movie the player just wouldn't move, I thought it may be to do with the fact that the variable_name was a string variable of either "-" or "+"
I would just re-write the code with the different operator, would seem the logical thing to do and then just change the conditions, but because there are so many movement statements that need to be controlled it would be to much code and a variable is the only logical way to control it. operator definition of operator in the Free Online Encyclopedia.:: See arithmetic operators and Boolean operator. Operators may also write the job control language (JCL), which schedules the daily work for the computer. http://encyclopedia2.thefreedictionary.com/operatorHOME | Chapter 12. Functions and Operators:: Date arithmetic operations require complete dates and do not work with You can exert more control over full-text searching behavior if you have a http://dewa03.unep.org/manuals/mysql/html-chapter/functions.htmlHOME |
anyone know what im doing wrong or if theres a specific way of representing operators?
(attached a demo of what im working on)
Why don't you use a boolean variable, like this:
on (keyPress.SPACE) {
_root.SpaceDown = TRUE;
}
on (keyUp.SPACE) {
_root.SpaceDown = FALSE;
}
if (Key.isDown(Key.UP) ) {
if (_root.SpaceDown) {
if (angle == 360) {
this._y -=10;
}
}else {
if (angle == 360) {
this._y +=10;
}
}
}
I tried to peice some of it together from the code you had... and my exact AS coding is a little rusty... but that's about the jist of it. 2.3. Operators: Arithmetic, Logical, and Conditional:: The C# operators used for arithmetic operations, bit manipulation, and conditional . Each case block must end with a statement that transfers control. http://www.codeguru.cn/dotnet/Core.C.Sharp.and.dot.NET/0131472275/ch02lev1sec3.htmlHOME | Programming Languages:: Jump to Arithmeticâ Ž: Set screen Arithmetic Operators This is commonly done in control systems to align bits that are read from, or to be written to, http://www.wilsonmar.com/1pgmlang.htmHOME |
+ and - cannot be manipulated in that way. You will need to find some other solution, either through method handling (i.e. this.moveFoward(speed, isReversed)) or something like SeiferTim suggested... though my approach would be more like
speed = 2;
reverse = (Key.isDown(Key.SPACE)) ? -1 : 1;
myHorzMvmnt = (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT))*speed*reverse;
It would work fine but the thing is I have 36 if statements controlling the movement in comparision to the player angle, so your method would mean writing 36 else statements and leading to to much code.
(the only reason I have 36 if statements is because I couldn't think of any mathematical calculation that would give me the movement for both X and Y in comparision to the angle of the player)
So I need to replace + or - with a variable which can then be reversed in everystatement in one go :-/
Where's The Advantage In Windows Genuine Advantage?
Stocks Bounce After S&P Joins Bear Market |