PDA

View Full Version : Multiple inputs not working?



Gleeok
11-08-2007, 08:01 AM
What the heck is wrong with this???


if((Link->InputRight) && (Link->InputDown)) {
This is the only if statement that actually does anything.
...So you can input directionally down-right and down-right only!?




if((Link->InputLeft) && (Link->InputUp)) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = -2;
fire1->Data = fcombo;
fire1->CSet = cset;
}
if((Link->InputRight) && (Link->InputUp)) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = 2;
fire1->Data = fcombo;
fire1->CSet = cset;
}
if((Link->InputLeft) && (Link->InputDown)) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y + 16;
fire1->Vx = -2;
fire1->Vy = 2;
fire1->Data = fcombo;
fire1->CSet = cset;
}
if((Link->InputRight) && (Link->InputDown)) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y + 16;
fire1->Vx = 2;
fire1->Vy = 2;
fire1->Data = fcombo;
fire1->CSet = cset;
}


How does the boomerang code work?

I'm basically trying to make the Metal Saw from Megaman 2, minus the boomerang part.

Saffith
11-08-2007, 10:18 AM
This is an item script, right?
Do you have any problems throwing the boomerang diagonally?

Gleeok
11-08-2007, 06:54 PM
Heh, from your post i'm guessing this is supposed to work. It is an item script, and I have tested the directional keys as well as the gamepad directions as well. The boomerang works fine.

I also tried if(Link->Dir == 4,5,6,7){ which didn't work.

Joe123
11-08-2007, 07:02 PM
How can Link's Direction be equal to 4, 5, 6 and 7?
It's an integer that ZC reads, it can't be equal to four values.

Saffith
11-08-2007, 09:08 PM
I see no reason at all why it shouldn't work. Entirely possible it's just a bug in the compiler, but I haven't been able to reproduce it so far.
You've already tried rewriting the same thing different ways, I take it? Maybe throw in some traces to be sure everything is as you'd expect... I don't know what else to suggest.

Gleeok
11-09-2007, 01:44 AM
How can Link's Direction be equal to 4, 5, 6 and 7?
It's an integer that ZC reads, it can't be equal to four values.

Thank you captain obvious. :p But seriously though...I'm just that good. :googly:




I see no reason at all why it shouldn't work. Entirely possible it's just a bug in the compiler, but I haven't been able to reproduce it so far.

You may be right. I admit that I must have been using trace wrong, so I debugged the old-fashioned way: I split every if statement into it's own script, which worked fine.



item script test1{

void run(int cset){

int fire_animation = 8;

ffc fire1 = Screen->LoadFFC(29);

if((Link->InputLeft) && (Link->InputUp)) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = -2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}}}


item script test2{

void run(int cset){

int fire_animation = 8;

ffc fire1 = Screen->LoadFFC(29);
if((Link->InputRight) && (Link->InputUp)) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = 2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}}}
item script test3{

void run(int cset){

int fire_animation = 8;

ffc fire1 = Screen->LoadFFC(29);

if((Link->InputLeft) && (Link->InputDown)) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y + 16;
fire1->Vx = -2;
fire1->Vy = 2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}}}

item script test4{

void run(int cset){

int fire_animation = 8;

ffc fire1 = Screen->LoadFFC(29);

if((Link->InputRight) && (Link->InputDown)) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y + 16;
fire1->Vx = 2;
fire1->Vy = 2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
}
}

I might just need to change the if statements to else if's, but I don't really understand why. In any case, here was the other version :



item script Halito{

void run(int cset){

int fire_animation = 8;

ffc fire1 = Screen->LoadFFC(29);
ffc fire2 = Screen->LoadFFC(28);
ffc fire3 = Screen->LoadFFC(27);
ffc fire4 = Screen->LoadFFC(26);
ffc fire5 = Screen->LoadFFC(25);

if(Link->MP >= 1 && halito_level == 1){


if(!(fire1->Data == fire_animation)){

Game->PlaySound(13);
Link->MP -= 1;
halito_exp++;

if((Link->InputLeft) && (Link->InputUp)) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = -2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if((Link->InputRight) && (Link->InputUp)) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = 2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if((Link->InputLeft) && (Link->InputDown)) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y + 16;
fire1->Vx = -2;
fire1->Vy = 2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if((Link->InputRight) && (Link->InputDown)) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y + 16;
fire1->Vx = 2;
fire1->Vy = 2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
else{

if(Link->Dir == 0) {
fire1->X = Link->X;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = 0;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if(Link->Dir == 1) {
fire1->X = Link->X;
fire1->Y = Link->Y + 16;
fire1->Vy = 2;
fire1->Vx = 0;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if(Link->Dir == 2) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y;
fire1->Vx = -2;
fire1->Vy = 0;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if(Link->Dir == 3) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y;
fire1->Vx = 2;
fire1->Vy = 0;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
}
}
else{
if(!(fire2->Data == fire_animation)){

Game->PlaySound(13);
Link->MP -= 1;

if(Link->Dir == 0) {
fire2->X = Link->X;
fire2->Y = Link->Y - 16;
fire2->Vy = -2;
fire2->Vx = 0;
fire2->Data = fire_animation;
fire2->CSet = cset;
}
if(Link->Dir == 1) {
fire2->X = Link->X;
fire2->Y = Link->Y + 16;
fire2->Vy = 2;
fire2->Vx = 0;
fire2->Data = fire_animation;
fire2->CSet = cset;
}
if(Link->Dir == 2) {
fire2->X = Link->X - 16;
fire2->Y = Link->Y;
fire2->Vx = -2;
fire2->Vy = 0;
fire2->Data = fire_animation;
fire2->CSet = cset;
}
if(Link->Dir == 3) {
fire2->X = Link->X + 16;
fire2->Y = Link->Y;
fire2->Vx = 2;
fire2->Vy = 0;
fire2->Data = fire_animation;
fire2->CSet = cset;
}
if(Link->Dir == 4) {
fire2->X = Link->X - 16;
fire2->Y = Link->Y - 16;
fire2->Vy = -2;
fire2->Vx = -2;
fire2->Data = fire_animation;
fire2->CSet = cset;
}
if(Link->Dir == 5) {
fire2->X = Link->X + 16;
fire2->Y = Link->Y - 16;
fire2->Vy = -2;
fire2->Vx = 2;
fire2->Data = fire_animation;
fire2->CSet = cset;
}
if(Link->Dir == 6) {
fire2->X = Link->X - 16;
fire2->Y = Link->Y + 16;
fire2->Vx = -2;
fire2->Vy = 2;
fire2->Data = fire_animation;
fire2->CSet = cset;
}
if(Link->Dir == 7) {
fire2->X = Link->X + 16;
fire2->Y = Link->Y + 16;
fire2->Vx = 2;
fire2->Vy = 2;
fire2->Data = fire_animation;
fire2->CSet = cset;
}
}
}
}
}
}


I should be able to fix it up now at least. Thanks for the help.

Saffith
11-09-2007, 03:23 AM
Ah. I think I see the problem now...

if((Link->InputLeft) && (Link->InputUp)) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = -2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if((Link->InputRight) && (Link->InputUp)) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = 2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if((Link->InputLeft) && (Link->InputDown)) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y + 16;
fire1->Vx = -2;
fire1->Vy = 2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if((Link->InputRight) && (Link->InputDown)) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y + 16;
fire1->Vx = 2;
fire1->Vy = 2;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
else{

if(Link->Dir == 0) {
fire1->X = Link->X;
fire1->Y = Link->Y - 16;
fire1->Vy = -2;
fire1->Vx = 0;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if(Link->Dir == 1) {
fire1->X = Link->X;
fire1->Y = Link->Y + 16;
fire1->Vy = 2;
fire1->Vx = 0;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if(Link->Dir == 2) {
fire1->X = Link->X - 16;
fire1->Y = Link->Y;
fire1->Vx = -2;
fire1->Vy = 0;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
if(Link->Dir == 3) {
fire1->X = Link->X + 16;
fire1->Y = Link->Y;
fire1->Vx = 2;
fire1->Vy = 0;
fire1->Data = fire_animation;
fire1->CSet = cset;
}
}
}



That else is only associated with the last of the four if statements. They are working, but since you're not holding down and right, it goes into the else part and overrides whatever it did earlier.
So just changing the ifs to else ifs should fix it.

C-Dawg
11-09-2007, 09:45 AM
I was able to get diagonal firing by checking Link->Dir and Link->Input(whatever). So if he's facing up and pushing left, it throws up and to the left. This gives you a little more control over the projectile, too. (12 directions instead of 8)

Gleeok
11-09-2007, 06:35 PM
I was able to get diagonal firing by checking Link->Dir and Link->Input(whatever). So if he's facing up and pushing left, it throws up and to the left. This gives you a little more control over the projectile, too. (12 directions instead of 8)

How the heck did you do that?

if Link->Dir up, and Link->InputRight. Then Link will be Dir right because Link->InputRight = false; ...only lasts for one frame on item scripts...I feel like i'm missing something though.

Is this a global script perhaps? I'll seriously be impressed if you got a 12 direction item script that works.