Annonce

>>> Bienvenue sur codelab! >>> Première visite ? >>> quelques mots sur codelab //// partage de liens //// une carte des membres//// (apéros) codelab


#1 2017-04-18 18:01:35 probleme variable class

imdidi
membre
Date d'inscription: 2012-10-05
Messages: 219

probleme variable class



salut a tous
je viens de découvrir les fichiers csv pour "sauvegarder" des paramètre. je load mes parametre jusqu'a la pas de probleme

void loadSetting(){
  int rowCount = 0;
  lightDefaultConfig = loadTable("lightDefaultConfig.csv", "header");
  light = new light[lightDefaultConfig.getRowCount()];
  
  for (TableRow row : lightDefaultConfig.rows()) {
    float x = row.getFloat("x");
    float y = row.getFloat("y");
    float x1 = row.getFloat("x1");
    float y1 = row.getFloat("y1");
    float sizeX = row.getFloat("sizeX");
    float sizeY = row.getFloat("sizeY");
    int lightId = row.getInt("lightID");
    int lightIsActive = row.getInt("lightIsActive");
    String lightType = row.getString("lightType");
   // println(lightType);
    light[rowCount] = new light(x,y,sizeX,sizeY, x1, y1, lightType);
    
    rowCount++;
  }
}

si je fais un println dans ma class je retrouve les variable il affiche les bon numero mais c'est comme si la variable etait vide elle n'es pas pris en compte dans la class
dans le " light[rowCount] = new light(x,y,sizeX,sizeY, x1, y1, lightType);
x,y,sizeX,sizeY sont correct pris en compte mais x1,y1,lightType me pose problème
si dans mon fichier csv le lightType est = "spot" dans ma class la variable lightType est aussi = a "spot" mais un de mes void showLight() est if(lightType == "spot") { la ca sa marche pas la variable lightType contient "spot" mais le if le vois pas si par contre dans le void setup je met light[0].setLightForm("spot") la mon void showlight() fonctionne

 

//****************************************************
public class light {
  float lightSelectionX, lightSelectionY, lightSelectionSizeX, lightSelectionSizeY, lightSelectionX1,lightSelectionY1, lightSelectionSizeX1, lightSelectionSizeY1;
  float oldLightSelectionX, oldLightSelectionX1, oldX, oldX1;
  boolean isPressed, isLight = false, isLink = false, topLedBar, isPressable = true;
  String lightType;

 
  light(float lightSelectionX_, float lightSelectionY_, float lightSelectionSizeX_, float lightSelectionSizeY_,float lightSelectionX1_, float lightSelectionY1_, String lightType_) {
    lightSelectionX = lightSelectionX_;
    lightSelectionY = lightSelectionY_;
    lightSelectionX1 = lightSelectionX1_;
    lightSelectionY1 = lightSelectionY1_;
    lightSelectionSizeX = lightSelectionSizeX_;
    lightSelectionSizeY = lightSelectionSizeY_;
    lightType = lightType_;
    if(lightSelectionX1 > 0 || lightSelectionY1 > 0) isLink = true; 
    else isLink = false; 
  }
  
  float lightSelectionX() { return lightSelectionX; }
  
  float lightSelectionY() { return lightSelectionY; }
  
  float lightSelectionX1() { return lightSelectionX1; }
  
  float lightSelectionY1() { return lightSelectionY1; }
   
  float lightSelectionSizeX1() { return lightSelectionSizeX1; }
  
  float lightSelectionSizeY1() { return lightSelectionSizeY1; }
  
  boolean isPressed(){ return isPressed; }
  
  boolean isLight(){ return isLight; }
    
  String lightType(){ return lightType; }
        
  void setlightType( String lightType_){ lightType = lightType_; }
  
  void setIsPressable(boolean _isPressable){ isPressable = _isPressable; }
  
  void setIsPressed(boolean _isPressed){ isPressed = _isPressed; }
  
  void setIsLight(boolean _isLight){ isLight = _isLight; }
  
  boolean overRect()  {
    if(!isLink) {
      if (mouseX >= lightSelectionX-(lightSelectionSizeX/2) && mouseX <= lightSelectionX+(lightSelectionSizeX/2) && 
          mouseY >= lightSelectionY-(lightSelectionSizeY/2) && mouseY <= lightSelectionY+(lightSelectionSizeY-20)) {
          return true; }
        return false; }
    else{
      if ((mouseX >= lightSelectionX-(lightSelectionSizeX/2) && mouseX <= lightSelectionX+(lightSelectionSizeX/2) && 
          mouseY >= lightSelectionY-(lightSelectionSizeY/2) && mouseY <= lightSelectionY+lightSelectionSizeY/*-30*/) ||
         (mouseX >= lightSelectionX1-(lightSelectionSizeX1/2) && mouseX <= lightSelectionX1+(lightSelectionSizeX1/2) && 
          mouseY >= lightSelectionY1-(lightSelectionSizeY1/2) && mouseY <= lightSelectionY1+lightSelectionSizeY1/*-30*/)) {
          return true;}
        return false; }
  } 
  
  void buttonPressed() {
    if((panel == 3 || panel == 4 || panel == 5) && isPressable){
      isLight = false;
      if(overRect()) isPressed = !isPressed; }
    else if(!preference && isPressed){
      if(overRect()) isLight = !isLight;   }
  }
  
  void lightSelection() {
    pushStyle();
    noFill();
    strokeWeight(2);
    stroke(0,0,255);
    if(!isLink) {
       rect(lightSelectionX(),lightSelectionY,lightSelectionSizeX,lightSelectionSizeX); 
    }
    else{
       rect(lightSelectionX,lightSelectionY ,lightSelectionSizeX,lightSelectionSizeY);  
       rect(lightSelectionX1(),lightSelectionY1() ,lightSelectionSizeX,lightSelectionSizeY); 
    }
    popStyle();
  }
  
  void showLight() {
    pushStyle();
    imageMode(CENTER);
    if(lightType() == "sealBeam") {
      if(isLink) {
        if(isLight) {
          image(squareLightOn, lightSelectionX, lightSelectionY, 64, 64);
          image(squareLightOn, lightSelectionX1, lightSelectionY1, 64, 64); }
        else{
          image(squareLightOff, lightSelectionX, lightSelectionY, 64, 64); 
          image(squareLightOff, lightSelectionX1, lightSelectionY1, 64, 64); }
      }
      else{
        if(isLight) {
          image(squareLightOn, lightSelectionX, lightSelectionY, 64, 64);  }
        else{
          image(squareLightOff, lightSelectionX, lightSelectionY, 64, 64); }
      }
    }
    else if(lightType() == "led") {
      if(topLedBar) {
        if(isLight) {
          image(topLedBarOn,lightSelectionX, lightSelectionY,lightSelectionSizeX,lightSelectionSizeY); }
        else{
          image(topLedBarOff,lightSelectionX, lightSelectionY,lightSelectionSizeX,lightSelectionSizeY); }
      }
      else{
        if(isLight) {
          image(bumperLedBarOn,lightSelectionX, lightSelectionY,lightSelectionSizeX,lightSelectionSizeY); }
        else{
          image(bumperLedBarOff,lightSelectionX, lightSelectionY,lightSelectionSizeX,lightSelectionSizeY); }
      }
    }
    
    else if(lightType() == "spot") {
      if(isLink) {
        if(isLight) {
          image(spotOn, lightSelectionX+2, lightSelectionY, 64, 64); 
          image(spotOn, lightSelectionX1+2, lightSelectionY1, 64, 64); }
        else{
          image(spotOff, lightSelectionX+2, lightSelectionY, 64, 64); 
          image(spotOff, lightSelectionX1+2, lightSelectionY1, 64, 64); }
      }
      else{
        if(isLight) {
          image(spotOn, lightSelectionX+2, lightSelectionY, 64, 64);  }
        else{
          image(spotOff, lightSelectionX+2, lightSelectionY, 64, 64);  }
      }
    }
    
    
    popStyle();
  }
  
  void test(){ println(lightSelectionX,lightSelectionY,lightSelectionX1,lightSelectionY1,lightSelectionSizeX,lightSelectionSizeY,isPr         essable, overRect(), isPressed, isLink, lightType);
    
  }
}

quelqu'un a déjà eu ce genre de problème ?

Hors ligne

 

#2 2017-04-18 19:35:03 Re : probleme variable class

Mushussu
membre
Lieu: Orléans
Date d'inscription: 2012-05-24
Messages: 732

Re: probleme variable class



Bonsoir,

C'est une histoire de pool des valeurs littérales.
C'est pour cela qu'il faut toujours utiliser la méthode equals() quand on compare deux instances de la classe String.
Dans ton cas :

if (lightType.equals("spot"))

Hors ligne

 

#3 2017-04-18 20:50:31 Re : probleme variable class

imdidi
membre
Date d'inscription: 2012-10-05
Messages: 219

Re: probleme variable class



ok cool merci
maintenant ca fonctionne

Hors ligne

 

fil rss de cette discussion : rss

Pied de page des forums

Powered by FluxBB

codelab, graphisme & code : emoc / 2008-2017