Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Using Loops to Change GUI Alpha (https://forums.graalonline.com/forums/showthread.php?t=134268493)

baseman101 07-20-2013 01:04 AM

Using Loops to Change GUI Alpha
 
I am trying to change the alpha of a tool on a staff tool bar I made for a UC server, so I used a for loop to do so. Originally, doing this would work:
PHP Code:

DoctorStaffBar_Control0.alpha 0.3;
DoctorStaffBar_Control1.alpha 0.3;
DoctorStaffBar_Control2.alpha 1;
DoctorStaffBar_Control3.alpha 0.3;
etc

Although my code got really long. So, I made a for loop and added a continue so that if the code got to the staff tool selected, the alpha would become 1. What's odd is that I echoed the code after I set the alpha, and it prints correctly. It doesn't show up on my GUI though. Yes, setting the text does work with this loop.
PHP Code:

function selectToolName(temp.staffCode) {
  
temp.code 0;
  for (
temp.blah getTools()) {
    if (
temp.code == temp.staffCode) {
      
temp.thing "DoctorStaffBar_Control" temp.staffCode;
      
DoctorStaffBar_Control_Text.text getTools()[temp.staffCode][0];
      
temp.thing.alpha 1;
      
temp.code++;
      continue;
    }
    
temp.thing "DoctorStaffBar_Control" temp.code;
    
temp.thing.alpha 0.3;
    
temp.code++;
  }



fowlplay4 07-20-2013 02:33 AM

Avoid using continue and break when you don't have to.

PHP Code:

function selectToolName(temp.staffCode) { 
  
temp.code 0;
  
temp.tools getTools();
  
DoctorStaffBar_Control_Text.text temp.tools[temp.staffCode][0];
  for (
temp.code 0temp.code temp.tools.size(); temp.code++) {
    
temp.thing = ("DoctorStaffBar_Control" temp.code); 
    if (
temp.code == temp.staffCode) { 
      
temp.thing.alpha 1
    } else {
      
temp.thing.alpha 0.3;
    }
  } 



baseman101 07-20-2013 02:45 AM

Hey,

Thanks for your quick reply! Unfortunately, this does not change the alpha of the image like I stated. I'll give you my full code if that helps.

PHP Code:

//Scripted by Graal801624

function onActionServerSide(cmdtemp.staffCode) {
  
//What happens if the player activates one of the tools.
  
if(cmd == "staffbar") {
    switch(
temp.staffCode) {
      case 
0:
        
//Boots
        
echo("The player activated Tool One");
      break;
      
      case 
1:
        
//Drag
        
echo("The player activated Tool Two");
      break;
      
      case 
2:
        
//Staff tag
        
echo("The player activated Tool Three");
      break;
      
      case 
3:
        
//Testing
        
echo("The player activated Tool Four");
      break;
    }
  }
}

//#CLIENTSIDE
function getTools() {
  
//In the return, type the tools with an image.
  
return {{"Tool 1","red.png"},{"Tool 2","orange.png"},{"Tool 3","yellow.png"},{"Tool 4","green.png"},{"Tool 5","blue.png"},{"Tool 6","purple.png"}};
}

function 
getDefAlpha() {
  
//Type here what you want the default non-selected alpha to be.
  
return 0.3;
}

function 
onCreated() {
  new 
GuiBitmapCtrl("DoctorStaffBar_Window") {
    
profile GuiDefaultProfile;
    
bitmap "black";
    
height 70;
    
width 400;
    
15;
    
= (GraalControl.height 115);
    
temp.int 0;
    
this.tools getTools();
    
temp.xaddgui 10;
    for (
temp.tools this.tools) {
      new 
GuiShowImgCtrl("DoctorStaffBar_Control" temp.int) {
        
temp.xaddgui;
        
30;
        
width 500;
        
height 30;
        
image getTools()[temp.int][1];
        
alpha getDefAlpha();
      }
      
temp.int++;
      
temp.xaddgui += 40;
    }
    new 
GuiShowImgCtrl("DoctorStaffBar_Control_Text") {
        
5;
        
0;
        
width 500;
        
height 30;
        
text getTools()[0][0];
      }
  }
  
this.staffCode 0;
  
DoctorStaffBar_Control0.alpha 1;
}

function 
onKeyPressed(keynamekeycode) {
  if(
keyname == 49) {
    
//Number 1
    
this.staffCode 0;
    
selectToolName(this.staffCode);
  }
  
  if(
keyname == 50) {
    
//Number 2
    
this.staffCode 1;
    
selectToolName(this.staffCode);
  }
  
  if(
keyname == 51) {
    
//Number 3
    
this.staffCode 2;
    
selectToolName(this.staffCode);
  }
  
  if(
keyname == 52) {
    
//Number 4
    
this.staffCode 3;
    
selectToolName(this.staffCode);
  }
  
  if(
keyname == 53) {
    
//Number 5
    
this.staffCode 4;
    
selectToolName(this.staffCode);
  }
  
  if(
keyname == 54) {
    
//Number 6
    
this.staffCode 5;
    
selectToolName(this.staffCode);
  }
  
  if(
keyname == 55) {
    
//Number 7
    
this.staffCode 6;
    
selectToolName(this.staffCode);
  }
  
  if(
keyname == 56) {
    
//Number 8
    
this.staffCode 7;
    
selectToolName(this.staffCode);
  }
  
  if(
keyname == 87) {
    
//Activate selected staff tool with w
    
triggerServer("gui"this.name"staffbar"this.staffCode);
  }
}

function 
selectToolName(temp.staffCode) { 
  
temp.code 0;
  
temp.tools getTools();
  
DoctorStaffBar_Control_Text.text temp.tools[temp.staffCode][0];
  for (
temp.code 0temp.code temp.tools.size(); temp.code++) {
    
temp.thing = ("DoctorStaffBar_Control" temp.code); 
    if (
temp.code == temp.staffCode) { 
      
temp.thing.alpha 1
    } else {
      
temp.thing.alpha getDefAlpha();
    }
  } 


Thanks,
The Doctor

fowlplay4 07-20-2013 06:28 AM

Change:

temp.thing = ("DoctorStaffBar_Control" @ temp.code);

To:

temp.thing = makevar("DoctorStaffBar_Control" @ temp.code);

KeyPress can be shortened, unless you plan to changing it from the number keys:

PHP Code:

function onKeyPressed(keycodekeyname) {
  
temp.code keycode 49;
  if (
temp.code getTools().size()) {
    
selectToolName(temp.code);
  }
  else if (
keycode == 87) {
    
//Activate selected staff tool with w
    
triggerServer("gui"this.name"staffbar"this.staffCode);
  }



baseman101 07-21-2013 04:21 AM

Hey,

Thanks for your help! I was wondering if there was a function to make a variable, thanks for pointing it out. Cheers! I'll post the whole script in the code gallery when I'm done :)

Quote:

Originally Posted by fowlplay4 (Post 1720811)
KeyPress can be shortened, unless you plan to changing it from the number keys:

PHP Code:

function onKeyPressed(keycodekeyname) {
  
temp.code keycode 49;
  if (
temp.code getTools().size()) {
    
selectToolName(temp.code);
  }
  else if (
keycode == 87) {
    
//Activate selected staff tool with w
    
triggerServer("gui"this.name"staffbar"this.staffCode);
  }



Yes, I had actually planned to change it in the future, but thanks for the snippet :)


All times are GMT +2. The time now is 06:25 AM.

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