Jump to content

Photo

Why is this not working?


  • Please log in to reply
5 replies to this topic

#1 Joe123

Joe123

    Retired

  • Members

Posted 28 September 2007 - 07:23 PM

CODE
if(Link->HP <=64 && Game->Counter[1] != 0){ //open if 1 (HP)
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(l);
                Link->InputL = false;
                }        //close if 1

                if(Game->Counter[1] == 0 && Link->HP !=64){    //open if 2 (Rupees)
                Game->Counter[1] = Game->Counter[1] +10;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(m);
                Link->InputL = false;
                }        //close if 2

                if(Link->HP <=64 && Game->Counter[1] == 0){ //open if 3 (HP & Rupees)
                Game->Counter[1] = 10;
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(n);
                Link->InputL = false;
                }        //close if 3

                if(Link->HP > 65 && Game->Counter[1] != 0){ //open if 4
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(o);
                Link->InputL = false;
                } //close if 4


I have this, inserted in the middle of Pkmnfrk's NPC script. It does the different functions (healing HP and all) fine, but for some reason it is determined to only play the one string (the last one) can anyone tell me why this is please?

#2 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 28 September 2007 - 10:40 PM

QUOTE(Joe123 @ Sep 28 2007, 06:23 PM) View Post


I will comment on certain lines of the script, not sure what is supposed to come before it though...


CODE
if(Link->HP <=64 && Game->Counter[1] != 0){ //less than four hearts = is set. (not at 0)
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(l);
                Link->InputL = false;
                }        //close if 1

                if(Game->Counter[1] == 0 && Link->HP !=64){//no rupees and do you mean !==64? or equals?
                Game->Counter[1] = Game->Counter[1] +10;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(m);
                Link->InputL = false;
                }        //close if 2

                if(Link->HP <=64 && Game->Counter[1] == 0){ //open if 3 (HP &     0    Rupees)
                Game->Counter[1] = 10;
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(n);
                Link->InputL = false;
                }        //close if 3

                if(Link->HP > 65 && Game->Counter[1] != 0){ //open if 4....64>=?
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(o);
                Link->InputL = false;
                } //close if 4


I have this, inserted in the middle of Pkmnfrk's NPC script. It does the different functions (healing HP and all) fine, but for some reason it is determined to only play the one string (the last one) can anyone tell me why this is please?





Oh...wait.....if you want only ONE of the if statements to open you have to add else.

if -IF was false then ELSE.

Actually try this

if(this is true){
Scounter =1}

if(that is true){
Scounter = 2

then at the end simply find which one was true:

This doesn't help you for this script though, sorry...
I just started using these for mega nested if statements to cut down on length.

try else.

#3 Joe123

Joe123

    Retired

  • Members

Posted 29 September 2007 - 04:24 AM

I had them running with else aswell as if beforehand, but that didn't work either, then after looking at it, I thought it shouldn't really need else.

And '!=' is 'not equal to' (isn't it?)

And I don't want is greater than or equal to 64 instead of is greater than 65 on that last bit, because it would clash with the one where it's 'is less than or equal to' 64.

I don't understand your scounters though I'm afraid.


EDIT: This doesn't work either... (I did declare Scounter as an integer at the start)
CODE
if(Link->HP <=64 && Game->Counter[1] > 0){ //open if 1 (HP)
                Scounter = 1;
                }        //close if 1
                else{
                if(Game->Counter[1] == 0 && Link->HP !=64){    //open if 2 (Rupees)
                Scounter = 2;
                }        //close if 2
                else{
                if(Link->HP <=64 && Game->Counter[1] == 0){ //open if 3 (HP & Rupees)
                Scounter = 3;
                }        //close if 3
                else{
                if(Link->HP > 65 && Game->Counter[1] > 0){ //open if 4
                Scounter = 4;
                } //close if 4
                }//else 1    
                } // else 2
                } // else 3

                if(Scounter == 4){
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(o);
                Link->InputL = false;
                }
                else{
                if(Scounter == 1){
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(l);
                Link->InputL = false;
                }
                else{
                if(Scounter == 2){
                Game->Counter[1] = Game->Counter[1] +10;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(m);
                Link->InputL = false;
                }
                else{
                if(Scounter == 3){
                Game->Counter[1] = 10;
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(n);
                Link->InputL = false;
                }    
                }
                }
                }


Edited by Joe123, 29 September 2007 - 04:50 AM.


#4 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 29 September 2007 - 06:00 AM

Yeah, nevermind that. I'm guessing you have this in a while loop...correct? Scripts can be picky, plus next time post the whole script maybe.

I'm scrayching my head at why there's the not zero rupees statements though.....? heh..i'm just trying to figure out what your using it for. Haha.

Here's a debug version, it should point to what's not working(if anything), or it should work...

CODE

int strung = false; // addd this right after void run(){

if (strung == false){

if(Link->HP <=64 && Game->Counter[1] != 0){ //open if 1 (HP)
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(l);
                Link->InputL = false;
        strung = true;
                }        //close if 1

                if(Game->Counter[1] == 0 && Link->HP !=64 && strung == false){    //open if 2 (Rupees)
                Game->Counter[1] = Game->Counter[1] +10;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(m);
                Link->InputL = false;
        strung = true;
                }        //close if 2

                if(Link->HP <=64 && Game->Counter[1] == 0 && strung == false){ //open if 3 (HP & Rupees)
                Game->Counter[1] = 10;
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(n);
                Link->InputL = false;
        strung = true;
                }        //close if 3

                if(Link->HP > 65 && Game->Counter[1] != 0 && strung == false){ //open if 4
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(o);
                Link->InputL = false;
        strung = true;
                } //close if 4
        } // close if strung



out of curiousity why the :

1-less than 4 >0
2-not 4 and == 0
3-less than 4 and 0
4-greater than 4 and not 0......???

#5 Joe123

Joe123

    Retired

  • Members

Posted 29 September 2007 - 06:15 PM

Right Gleeok, you asked for it icon_razz.gif

CODE
ffc script real_npc_heal_ammo { //open script
    void run(int s, int f, int d, int def_dir, int l, int m, int n, int o) { //open void run
        
        int d_x;
        int d_y;
        int a_x;
        int a_y;
        int orig_d = this->Data;
        int Scounter;
        
        if(d == 0) d = 48;
        
        
        while(true) { //open while loop
            d_x = this->X - Link->X;
            d_y = this->Y - Link->Y;
            a_x = Abs(d_x);
            a_y = Abs(d_y);
            
            if(f != 0) { //open if
                if(a_x < d && a_y < d) { //open if
                    if(a_x <= a_y) { // open if
                        if(d_y >= 0) { //open if
                            this->Data = orig_d + DIR_UP;
                        } else { //close if open else
                            this->Data = orig_d + DIR_DOWN;
                        } // close else
                    } else { //close if open else
                        if(d_x >= 0) { //open if
                            this->Data = orig_d + DIR_LEFT;
                        } else { //close if open else
                            this->Data = orig_d + DIR_RIGHT;
                        } //close else
                    } //close if
                } else { //close if open else
                    this->Data = orig_d + def_dir;
                } //close if
            } //close if
            
            if(Link->InputL && a_x < 24 && a_y < 24) {
                

                if(Link->HP <=64 && Game->Counter[1] > 0){ //open if 1 (HP)
                Scounter = 1;
                }        //close if 1

                if(Game->Counter[1] == 0 && Link->HP !=64){    //open if 2 (Rupees)
                Scounter = 2;
                }        //close if 2

                if(Link->HP <=64 && Game->Counter[1] == 0){ //open if 3 (HP & Rupees)
                Scounter = 3;
                }        //close if 3

                if(Link->HP > 65 && Game->Counter[1] > 0){ //open if 4
                Scounter = 4;
                } //close if 4

                if(Scounter == 4){
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(o);
                Link->InputL = false;
                }
                
                if(Scounter == 1){
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(l);
                Link->InputL = false;
                }
                
                if(Scounter == 2){
                Game->Counter[1] = Game->Counter[1] +10;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(m);
                Link->InputL = false;
                }
            
                if(Scounter == 3){
                Game->Counter[1] = 10;
                Link->HP = Link->HP +80;
                Link->MP = Link->MP +256;
                if(s != 0) Game->PlaySound(s);
                Screen->Message(n);
                Link->InputL = false;
                }    

                } // close if

            Waitframe();
        } // close while loop
    } //close void run
} //close script


Bam. Pkmnfrk's NPC script, modified so that it should
1) If Link has some rupees, and more than 4 health (Link->HP > 65 && Game->Counter[1] > 0)
Give Link all his MP back, and play string 1.
2) If Link has no rupees, and more than 4 health (Game->Counter[1] == 0 && Link->HP > 64)
Give Link all his MP back, give him 10 rupees and play string 2
3) If Link has some rupees, and less than 4 health (Link->HP <=64 && Game->Counter[1] > 0)
Give Link all his MP back, give him 4 health and play string 3
4) If Link has no rupees, and less than 4 health (Link->HP <=64 && Game->Counter[1] == 0)
Give Link all his MP back, give him 4 health, 10 rupees and play string 4.

WHY DOES THIS NOT HAPPEN?! THE IF STATEMENTS ARE MUTUALLY EXCLUSIVE! GAHHHHHH!


also, what's the 'strung' thing meant to do icon_confused2.gif

Edited by Joe123, 29 September 2007 - 06:19 PM.


#6 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 29 September 2007 - 07:35 PM

Yep, that's what I thought. Here's why it WONT work:

the while(true) loops.....FOREVER.hahahahaha!!!

...so here's what happens, It sees that Link has less hit points and gives him some, then it sees that Link has more hit points and plays

String(m);
String(n);

But it will always play the last. To fix that you need an on/off switch. That's why I added int strung.

Notice that if any string plays, int strung becomes true, shutting down that portion of the loop.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users