Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-07-2011, 04:35 AM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
Help with a for loop problem?

Okay so, I'm using a for loop to check through a multi-dimensional array, and everything is returning fine, the script is basically doing what I want it to do, no problem. But now within the for loop i'm trying to set an individual this.whatever flag everytime I mouse over an object in the array. (If this makes sense?) But for some reason, I can only set the flag for the last group of variables in the array.. ?

I dunno if what I just said makes any sense, but either way, check out the code and you'll probably see what I mean.. By the way, I am merely providing the pieces of the code that are needed in order for me to get help, the //Mouse Over part is being ran within a timeout loop just to clarify things a bit more..

Also, another clarification: I'm trying to set this.newDebug to true everytime the mouse enters the specified zone, but I can only set it for the "Rifle" array part. It won't set for any others. =/

Thanks in advance to anyone that helps.

PHP Code:
function onCreated()
{
  
this.equipSlots = { {"Hat"3658"necro_gui_equips-hat.png"},
                      {
"Mask"9658"necro_gui_equips-mask.png"},
                      {
"Armor"15658"necro_gui_equips-armor.png"},
                      {
"Back Piece"36118"necro_gui_equips-back.png"},
                      {
"Shirt"156118"necro_gui_equips-shirt.png"},
                      {
"Glove"36178"necro_gui_equips-glove.png"},
                      {
"Pants"156178"necro_gui_equips-pants.png"},
                      {
"Shoes"96209"necro_gui_equips-shoes.png"},
                      {
"Explosive"36233"necro_gui_equips-explosive.png"},
                      {
"Left Weapon"36288"necro_gui_equips-leftwep.png"},
                      {
"Right Weapon"156288"necro_gui_equips-rightwep.png"},
                      {
"Rifle"96264"necro_gui_equips-rifle.png"}
                   };
  
this.equipSlotCount 12;
}

    
//Mouse over for Slot
    
temp.mouse_xy = {mousescreenxmousescreeny};
    for ( 
i=0this.equipSlotCounti++; ) {
      
      
temp.chSlots this.equipSlots[i];
      if ( 
mouse_xy[0in |menu_xy[0] + chSlots[1], menu_xy[0] + chSlots[1] + 32| &&
           
mouse_xy[1in |menu_xy[1] + chSlots[2], menu_xy[1] + chSlots[2] + 32| ) {
        
this.newDebug true;
        
with findImg 203 ) ) {
        
          
image chSlots[3];
          
menu_xy[0] + chSlots[1];
          
menu_xy[1] + chSlots[2];
          
layer 5;
          
mode 0;
          
red green blue 1;
          
alpha .8;
        }
        
with findImg 223 ) ) {
        
          
text chSlots[0];
          
font "Tempus Sans ITC";
          
style "bc";
          
menu_xy[0] + chSlots[1] + 16;
          
menu_xy[1] + chSlots[2] - 5;
          
layer 5;
          
mode 0;
          
red green blue 1;
          
alpha .8;
          
textshadow true;
          
shadowcolor = {000};
          
zoom .6;
        }
      } else {       
        
hideImg203 ); 
        
hideImg223 ); 
        
this.newDebug false;
      }
    } 
Reply With Quote
  #2  
Old 06-07-2011, 04:44 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
The reason it only works for the rifle is because it is the last member of the array. It is being set to true properly for the rest of them, but you're also immediately setting it back to false in the next loop iteration.

Try breaking out of the loop after you set it to true (and have performed all of your logic).

edit: if you still need to hide remaining images, play with hideImgs(start, end). There's really no need to continue looping to hide the rest of the images because you know exactly how many you have
PHP Code:
// Hide remaining images
hideImgs(203 1203 this.equipSlotCount);
hideImgs(223 1223 this.equipSlotCount);

break; 
// break out of your loop 
might have failed at math, but you get the idea
__________________

Last edited by salesman; 06-07-2011 at 05:04 AM..
Reply With Quote
  #3  
Old 06-07-2011, 05:02 AM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
Quote:
Originally Posted by salesman View Post
The reason it only works for the rifle is because it is the last member of the array. It is being set to true properly for the rest of them, but you're also immediately setting it back to false in the next loop iteration.

Try breaking out of the loop after you set it to true (and have performed all of your logic).
How exactly would I break out of the loop though, I don't really get it.
Reply With Quote
  #4  
Old 06-07-2011, 05:06 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by DeCeaseD View Post
How exactly would I break out of the loop though, I don't really get it.
Something like this, although I haven't tested obviously:

PHP Code:
    //Mouse over for Slot
    
this.newDebug false// assume false
    
temp.mouse_xy = {mousescreenxmousescreeny};
    for ( 
i=0this.equipSlotCounti++; ) {
      
temp.chSlots this.equipSlots[i];
      if ( 
mouse_xy[0in |menu_xy[0] + chSlots[1], menu_xy[0] + chSlots[1] + 32| &&
           
mouse_xy[1in |menu_xy[1] + chSlots[2], menu_xy[1] + chSlots[2] + 32| ) {
        
this.newDebug true;

        
///// snip your image stuff //////

        // Hide remaining images
        
hideImgs(203 1203 this.equipSlotCount);
        
hideImgs(223 1223 this.equipSlotCount);

        
// break out of the loop b/c we only have one mouse location and we already know which object it's hovering over
        
break;
      } else { 
// Keep this to hide the images before we find one that's true   
        
hideImg(203 i); 
        
hideImg(223 i);
      }
    } 
__________________
Reply With Quote
  #5  
Old 06-07-2011, 05:12 AM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
Wow.. stupid of me. When you said to break out of the loop for someone reason I was thinking of something totally different. Forgot all about break; *****. But all I needed to do was assume it false like you said, than break out of the loop. Thanks alot Sales! ily!
Reply With Quote
  #6  
Old 06-07-2011, 05:14 AM
salesman salesman is offline
Finger lickin' good.
salesman's Avatar
Join Date: Nov 2008
Location: Colorado
Posts: 1,865
salesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud ofsalesman has much to be proud of
Quote:
Originally Posted by DeCeaseD View Post
Wow.. stupid of me. When you said to break out of the loop for someone reason I was thinking of something totally different. Forgot all about break; *****. But all I needed to do was assume it false like you said, than break out of the loop. Thanks alot Sales! ily!
=p
Keep in mind that if you just simply break out of the loop you're no longer hiding the remaining images, so you'll need to do something about that like I showed above.
__________________
Reply With Quote
  #7  
Old 06-07-2011, 05:47 AM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
Quote:
Originally Posted by salesman View Post
=p
Keep in mind that if you just simply break out of the loop you're no longer hiding the remaining images, so you'll need to do something about that like I showed above.
Yeah I got it.

But aside from that, I've ran into another odd issue..

I'm making this menu fade in/out when opened/closed, using this.menu_alpha, increasing and decreasing the value. It all works fine. Except now i've tried to add an actor into the middle of the menu, but the problem being that I can't seem to get it to fade with the menu:

PHP Code:
    with findImg300 ) ) {
    
      
ani "necro_body_idle";
      
menu_xy[0] + getimgWidth("necro_gui_equips.png")/2.53;
      
menu_xy[1] + getimgHeight("necro_gui_equips.png")/2.6;
      
dir 2;
      
layer 5;
      
mode 1;
      
red green blue 1;
      
partx 0;
      
party 0;
      
partw 41;
      
parth 68;
      
actor.attr[1] = player.attr[1];
      
actor.attr[2] = player.attr[2];
      
actor.attr[3] = player.attr[3];
      
actor.attr[4] = player.attr[4];
      
actor.attr[5] = player.attr[5];
      
actor.attr[6] = player.attr[6];
      
actor.attr[7] = player.attr[7];
      
actor.attr[8] = player.attr[8];
      
actor.attr[9] = player.attr[9];
      
actor.attr[10] = player.attr[10];
      
actor.attr[11] = player.attr[11];
      
actor.attr[12] = player.attr[12];
      
actor.attr[13] = player.attr[13];
      
actor.attr[14] = player.attr[14];
    } 
That's the code i'm using to display the actor, I can see it fine but the alpha won't change like I want it to. I'm using findImg( 300 ).alpha = this.menu_alpha; Any idea why it won't fade with the menu? :x
Reply With Quote
  #8  
Old 06-07-2011, 06:17 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by DeCeaseD View Post
That's the code i'm using to display the actor, I can see it fine but the alpha won't change like I want it to. I'm using findImg( 300 ).alpha = this.menu_alpha; Any idea why it won't fade with the menu? :x
this.menu_alpha is most likely 0/NULL in the context/scope of the findimg.

thiso.menu_alpha is what you're aiming for.
__________________
Quote:
Reply With Quote
  #9  
Old 06-07-2011, 05:12 PM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
Quote:
Originally Posted by fowlplay4 View Post
this.menu_alpha is most likely 0/NULL in the context/scope of the findimg.

thiso.menu_alpha is what you're aiming for.
I've actually already tried using thiso. But it's not the problem. I've found that you only need to use thiso. in context with findimg when you're setting something within the original 'with (findImg( index ) )', otherwise you can normally use this. by setting whatever findImg( index ).part = whatever;

Any ideas as to what else the problem could be?
Reply With Quote
  #10  
Old 06-08-2011, 03:30 AM
DeCeaseD DeCeaseD is offline
Registered User
Join Date: Jan 2008
Posts: 247
DeCeaseD will become famous soon enough
Anyone? No one?
Reply With Quote
  #11  
Old 06-08-2011, 06:06 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You could try using a gani script. I.e:

actor.attr[30] = "alpha.gani,0.5";

Gani: alpha.gani

PHP Code:
SCRIPT
function onPlayerEnters() {
  
player.alpha params[0];
}
SCRIPTEND 
It might be bugged though, I remember a similar problem.
__________________
Quote:
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 02:13 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.