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 07-20-2013, 01:04 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
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++;
  }

Reply With Quote
  #2  
Old 07-20-2013, 02:33 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
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;
    }
  } 

__________________
Quote:
Reply With Quote
  #3  
Old 07-20-2013, 02:45 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
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
Reply With Quote
  #4  
Old 07-20-2013, 06:28 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
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);
  }

__________________
Quote:
Reply With Quote
  #5  
Old 07-21-2013, 04:21 AM
baseman101 baseman101 is offline
Scripter
baseman101's Avatar
Join Date: Nov 2012
Location: Purcellville, VA
Posts: 76
baseman101 will become famous soon enough
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 View Post
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
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 07:47 AM.


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