Problema al hacer un if....

Moderadores: Kravenbcn, largeroliker, fidelcastro, cerealkiller, pspCaracas, dark_sasuke, m0skit0, LnD, ka69, zacky06

Avatar de Usuario
Dark_Miguel
Desarrollador
Desarrollador
Mensajes: 63
Registrado: 12 May 2010, 22:26
PSN ID: Ninguna, pronto me creo una....
Ubicación: Spain, Andalucía. Jaén
Contactar:

Problema al hacer un if....

Mensaje por Dark_Miguel »

Hola chicos, hantes de nada aclarar que el código que voy a poner es una modificación del example de la libreria de DAX. Bueno a lo que voy este es el codigo:

Spoiler:

Código: Seleccionar todo

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspsuspend.h>
#include <psppower.h>
#include <pspreg.h>
#include <psprtc.h>
#include <psputils.h>
#include <pspgu.h>
#include <pspgum.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <malloc.h>

#include <vlf.h>

PSP_MODULE_INFO("Translator Of Errors Beta Version C VLF", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(0);

// Callbacks
int ExitCallback(int arg1, int arg2, void *common)
{
    sceKernelExitGame();
    return 0;
}

int CallbackThread(SceSize args, void *argp)
{
    int callback_id;
    callback_id = sceKernelCreateCallback("Exit Callback", ExitCallback, NULL);
    sceKernelRegisterExitCallback(callback_id);
    sceKernelSleepThreadCB();
    return 0;
}

int SetupCallback(void)
{
    int thread_id = 0;
    thread_id = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, THREAD_ATTR_USER, 0);
    if (thread_id >= 0)
   {
        sceKernelStartThread(thread_id, 0, 0);
    }
    return thread_id;
}



typedef struct _SampleConfiguration
{
   u16 username[32];
   u16 password[32];
} SampleConfiguration;

char *license_text =
"Translator Of Errors Beta Versión C\n\n"

"¡Este homebrew participa en el\n"
"SceneryBeta2010 si te ha gustado\n"
"ingresa en la web PSP.SceneBeta.Com\n"
"y bota por él!\n\n"

"Creado por:\n"
"Dark-Miguel\n\n"
   
"Diseñado por:\n"
"Dark-Miguel y GerMaX\n\n"

"WebSite:\n"
"http://www.Dark-Miguel.vacau.com\n\n"

"WebFriends:\n"
"PSPStaTion.org, DaXHorDes.org\n"
"&\n"
"PSP.SceneBeta.com\n\n"

"Agradecimientos a:\n"
"Dark-AleX por su librería VLF\n"
"y por todo su trabajo en la scene,\n"
"Dark_Mizar & Germax\n"
"_____________________________________\n\n"

"Este homebre ha sido creado por Drak-Miguel\n"
"usando la librería VLF y el example de DaX\n"
"y otras inclidad en el SDK.\n\n"
"Si tiene alguna sugerencia por favor envie\n"
"un email a Dark_Miguel@hotmail.es"
;
      
SampleConfiguration config;
VlfPicture wall, wall1, logo;      
      
VlfText license, do_you_agree, title, titleV,prueba;

int focus;
VlfText username_label, password_label, rp_label, signin;
VlfInputBox username, password;
VlfCheckBox rp;

int OnExit(int enter)
{
   if (enter)
      sceKernelExitGame();
   
   return VLF_EV_RET_NOTHING;
}

void OnSaveConfig(void *param)
{
   int savepassword = (int)param;
   
   if (!savepassword)
      memset(config.password, 0, 32);
   
   SceUID fd = sceIoOpen("config.bin", PSP_O_WRONLY | PSP_O_TRUNC | PSP_O_CREAT, 0777);
   sceIoWrite(fd, &config, sizeof(SampleConfiguration));
   sceIoClose(fd);
}

void OnLoginFadeOutComplete(void *param)
{
   // Destruct old items
   vlfGuiCancelBottomDialog();
   vlfGuiRemoveText(username_label);
   vlfGuiRemoveText(password_label);
   vlfGuiRemoveText(rp_label);
   vlfGuiRemoveText(signin);
   vlfGuiRemoveInputBox(username);
   vlfGuiRemoveInputBox(password);
   vlfGuiRemoveCheckBox(rp);

   //aqui iría el if...

   vlfGuiSetRectangleFade(0, VLF_TITLEBAR_HEIGHT, 480, 272-VLF_TITLEBAR_HEIGHT, VLF_FADE_MODE_IN, VLF_FADE_SPEED_SUPER_FAST, 0, OnSaveConfig, param, 0);
}

int OnLoginScreenUp(void *param)
{
   switch (focus)
   {
      case 1:
         focus = 0;
         vlfGuiSetInputBoxFocus(password, 0);
         vlfGuiSetInputBoxFocus(username, 1);
         break;
      
      case 2:
         focus = 1;
         vlfGuiSetCheckBoxFocus(rp, 0);
         vlfGuiSetInputBoxFocus(password, 1);
         break;
      
      case 3:
         focus = 2;
         vlfGuiRemoveTextFocus(signin, 1);
         vlfGuiSetCheckBoxFocus(rp, 1);
         break;
   }
   
   return VLF_EV_RET_NOTHING;
}

int OnLoginScreenDown(void *param)
{
   switch (focus)
   {
      case 0:
         focus = 1;
         vlfGuiSetInputBoxFocus(username, 0);
         vlfGuiSetInputBoxFocus(password, 1);
         break;
      
      case 1:
         focus = 2;
         vlfGuiSetInputBoxFocus(password, 0);
         vlfGuiSetCheckBoxFocus(rp, 1);
         break;
      
      case 2:
         focus = 3;
         vlfGuiSetCheckBoxFocus(rp, 0);
         vlfGuiSetTextFocus(signin);
         break;
   }
   
   return VLF_EV_RET_NOTHING;
}

int OnLogin(int enter)
{
   if (enter)
   {
      if (focus == 3)
      {         
         vlfGuiGetInputBoxText(username, config.username);
         
         if (config.username[0] == 0)
         {
            vlfGuiMessageDialog("No has puesto ningun error!", VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
            return VLF_EV_RET_NOTHING;
         }
         
         vlfGuiGetInputBoxText(password, config.password);
         
         if (config.password[0] == 0)
         {
            vlfGuiMessageDialog("No has puesto el Cod. De Conf.", VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
            return VLF_EV_RET_NOTHING;
         }
         
         vlfGuiRemoveEventHandler(OnLoginScreenUp);
         vlfGuiRemoveEventHandler(OnLoginScreenDown);
         
         vlfGuiSetRectangleFade(0, VLF_TITLEBAR_HEIGHT, 480, 272-VLF_TITLEBAR_HEIGHT, VLF_FADE_MODE_OUT, VLF_FADE_SPEED_SUPER_FAST, 0, OnLoginFadeOutComplete, (void *)vlfGuiIsCheckBoxChecked(rp), 0);
         
         return VLF_EV_RET_REMOVE_HANDLERS;
      }
   }
   else
   {
      sceKernelExitGame();
   }
   
   return VLF_EV_RET_NOTHING;
}

void OnLicenseAgreementFadeOutComplete(void *param)
{
   // Destruct old items   
   vlfGuiRemoveText(license);
   vlfGuiRemoveText(do_you_agree);
   vlfGuiCancelBottomDialog();
   
   // Construct new items
   vlfGuiBottomDialog(VLF_DI_CANCEL, VLF_DI_ENTER, 1, 0, VLF_DEFAULT, OnLogin);
   
   username = vlfGuiAddInputBox("Escribe el error a buscar", 64, 65);
   password = vlfGuiAddInputBox("Escribe el Codigo De Confirmación", 64, 115);
   username_label = vlfGuiAddText(87, 45, "Error al Buscar");
   password_label = vlfGuiAddText(87, 95, "Codigo Conformación");   
   rp = vlfGuiAddCheckBox(70, 150);
   rp_label = vlfGuiAddText(95, 153, "Recordar Cododigo de Confirmación");
   signin = vlfGuiAddText(240, 195, "Buscar");
   
   vlfGuiSetTextFontSize(username_label, 0.75f);
   vlfGuiSetTextFontSize(password_label, 0.75f);
   vlfGuiSetTextAlignment(signin, VLF_ALIGNMENT_CENTER);
   vlfGuiSetInputBoxType(password, VLF_INPUTBOX_TYPE_PASSWORD);
   vlfGuiSetInputBoxTextW(username, config.username);
   vlfGuiSetInputBoxTextW(password, config.password);
   
   if (config.username[0] == 0)
   {
      vlfGuiSetInputBoxFocus(password, 0);
      focus = 0;
   }
   else if (config.password[0] == 0)
   {
      vlfGuiSetInputBoxFocus(username, 0);
      focus = 1;
   }
   else
   {
      vlfGuiSetInputBoxFocus(username, 0);
      vlfGuiSetInputBoxFocus(password, 0);
      vlfGuiSetCheckBoxCheck(rp, 1);
      vlfGuiSetTextFocus(signin);
      focus = 3;
   }
   
   vlfGuiAddEventHandler(PSP_CTRL_UP, 0, OnLoginScreenUp, NULL);
   vlfGuiAddEventHandler(PSP_CTRL_DOWN, 0, OnLoginScreenDown, NULL);
   
   vlfGuiSetRectangleFade(0, VLF_TITLEBAR_HEIGHT, 480, 272-VLF_TITLEBAR_HEIGHT, VLF_FADE_MODE_IN, VLF_FADE_SPEED_SUPER_FAST, 0, NULL, NULL, 0);   
}

int OnLicenseAgreement(int enter)
{
   if (enter)
   {
      vlfGuiSetRectangleFade(0, VLF_TITLEBAR_HEIGHT, 480, 272-VLF_TITLEBAR_HEIGHT, VLF_FADE_MODE_OUT, VLF_FADE_SPEED_SUPER_FAST, 0, OnLicenseAgreementFadeOutComplete, NULL, 0);
      return VLF_EV_RET_REMOVE_HANDLERS;
   }
   
   sceKernelExitGame();
   
   return VLF_EV_RET_NOTHING;
}
      
void StartSample()
{
   license = vlfGuiAddText(100, 40, license_text);         
   vlfGuiSetTextScrollBar(license,  40);
   
   do_you_agree = vlfGuiAddText(240, 210, "¿Deseas continuar?");
   vlfGuiSetTextAlignment(do_you_agree, VLF_ALIGNMENT_CENTER);
   vlfGuiBottomDialog(VLF_DI_CANCEL, VLF_DI_ENTER, 1, 0, VLF_DEFAULT, OnLicenseAgreement);
   
   vlfGuiSetRectangleFade(0, VLF_TITLEBAR_HEIGHT, 480, 272-VLF_TITLEBAR_HEIGHT, VLF_FADE_MODE_IN, VLF_FADE_SPEED_SUPER_FAST, 0, NULL, NULL, 0);
}

int menu_sel(int sel)
{
   switch (sel)
   {
      case 0:         
         StartSample();
         vlfGuiCancelPictureFade(logo);
         vlfGuiRemovePicture(logo);   
         vlfGuiCancelPictureFade(wall);
         vlfGuiRemovePicture(wall);   
      return VLF_EV_RET_REMOVE_HANDLERS | VLF_EV_RET_REMOVE_OBJECTS;
      
      case 1:
         sceKernelExitGame();
      break;
   }
   
   return VLF_EV_RET_NOTHING;
}

int app_main(int argc, char *argv[])
{

   wall = vlfGuiAddPictureFile("SceneryBeta2010.png", 0, 0);
   vlfGuiSetPictureFade(wall, VLF_FADE_MODE_OUT, VLF_FADE_SPEED_STANDARD, 0);

   char *items[] = { "Comenzar Busqueda", "Salir" };
   
   SetupCallback();
   title = vlfGuiAddText(0, 0, "   ");
   titleV = vlfGuiAddText(240, 0, "Translator Of Errors Beta Version C VLF");
   vlfGuiSetTextAlignment(titleV, VLF_ALIGNMENT_CENTER);
   vlfGuiSetTitleBar(title, 0, 1, 0);
   vlfGuiSetBackgroundPlane(0xFF901E);
   vlfGuiSetModelSystem(); //FFBF00
   vlfGuiLateralMenuEx(2, items, 0, menu_sel, 110,0xE08B0000);
   
   
   
   logo = vlfGuiAddPictureFile("logo.png", 35, 100); // png's are now supported
   vlfGuiSetPictureFade(logo, VLF_FADE_MODE_IN, VLF_FADE_SPEED_SLOW, 0);
   
   SceUID fd = sceIoOpen("config.bin", PSP_O_RDONLY, 0);
   if (fd >= 0)
   {
      sceIoRead(fd, &config, sizeof(SampleConfiguration));
      sceIoClose(fd);
   }
   
   while (1)
   {
      vlfGuiDrawFrame();
   }
   
   return 0;
}



Tengo un problema en este apartado:
Spoiler:

Código: Seleccionar todo

void OnLoginFadeOutComplete(void *param)
{
   // Destruct old items
   vlfGuiCancelBottomDialog();
   vlfGuiRemoveText(username_label);
   vlfGuiRemoveText(password_label);
   vlfGuiRemoveText(rp_label);
   vlfGuiRemoveText(signin);
   vlfGuiRemoveInputBox(username);
   vlfGuiRemoveInputBox(password);
   vlfGuiRemoveCheckBox(rp);
   
   // Construct new items
   vlfGuiCustomBottomDialog(NULL, "Exit", 1, 0, VLF_DEFAULT, OnExit);   
   
//aqui iría el if...

   vlfGuiSetRectangleFade(0, VLF_TITLEBAR_HEIGHT, 480, 272-VLF_TITLEBAR_HEIGHT, VLF_FADE_MODE_IN, VLF_FADE_SPEED_SUPER_FAST, 0, OnSaveConfig, param, 0);
}


Lo que quiero hacer es que si lo que escribo en el primer box es 400 sucede algo... Pero no se como hacerlo!!
Última edición por Dark_Miguel el 30 Jun 2010, 02:28, editado 2 veces en total.
Imagen

Avatar de Usuario
m0skit0
Administrador
Administrador
Mensajes: 5585
Registrado: 03 Sep 2009, 09:35
Ubicación: 0xdeadbeef

Re: Problema al hacer un if....

Mensaje por m0skit0 »

Me vas a perdonar, pero esto es de parvularios de programación...

¿config.username de qué tipo es? Me juego el pellejo a que es char*.
Imagen

Avatar de Usuario
Dark_Miguel
Desarrollador
Desarrollador
Mensajes: 63
Registrado: 12 May 2010, 22:26
PSN ID: Ninguna, pronto me creo una....
Ubicación: Spain, Andalucía. Jaén
Contactar:

Re: Problema al hacer un if....

Mensaje por Dark_Miguel »

m0skit0 escribió:Me vas a perdonar, pero esto es de parvularios de programación...

¿config.username de qué tipo es? Me juego el pellejo a que es char*.


Ya he editado el post, por alguna razón había unas cosas que no deberían de aparecer. Puedes volver a revisarlo?. Gracias.
Imagen

Avatar de Usuario
m0skit0
Administrador
Administrador
Mensajes: 5585
Registrado: 03 Sep 2009, 09:35
Ubicación: 0xdeadbeef

Re: Problema al hacer un if....

Mensaje por m0skit0 »

Yo no tengo ni idea de VLF, pero vamos a ver:

Código: Seleccionar todo

typedef struct _SampleConfiguration
{
   u16 username[32];
   u16 password[32];
} SampleConfiguration;

Yo veo que el registro username del struct _SampleConfiguration es un array de 32 posiciones. No entiende qué pretendes con config.username[400], cuando el array no tiene ese tamaño... Además, para comparar con un número como 400 tendrías que primero convertir ese array Unicode a un número entero, o bien comparar con una cadena Unicode "400" (no un número).
Imagen

Avatar de Usuario
Dark_Miguel
Desarrollador
Desarrollador
Mensajes: 63
Registrado: 12 May 2010, 22:26
PSN ID: Ninguna, pronto me creo una....
Ubicación: Spain, Andalucía. Jaén
Contactar:

Re: Problema al hacer un if....

Mensaje por Dark_Miguel »

:shock: Gracias tio no me habia dado cuenta que tenia puesto un array de 32 :lol:

Bueno ya he solucionado el problema en parte ya que en la forma password si voy a usar numeros pero en username no...
Imagen

Avatar de Usuario
m0skit0
Administrador
Administrador
Mensajes: 5585
Registrado: 03 Sep 2009, 09:35
Ubicación: 0xdeadbeef

Re: Problema al hacer un if....

Mensaje por m0skit0 »

Los números dan igual, son caracteres igualmente... Pero como veas ;)
Imagen

Avatar de Usuario
Dark_Miguel
Desarrollador
Desarrollador
Mensajes: 63
Registrado: 12 May 2010, 22:26
PSN ID: Ninguna, pronto me creo una....
Ubicación: Spain, Andalucía. Jaén
Contactar:

Re: Problema al hacer un if....

Mensaje por Dark_Miguel »

Creo que no me has entendido....

La solución a mi problema en parte es esta:
Spoiler:

Código: Seleccionar todo

void OnLoginFadeOutComplete(void *param)
{
   // Destruct old items
   vlfGuiCancelBottomDialog();
   vlfGuiRemoveText(username_label);
   vlfGuiRemoveText(password_label);
   vlfGuiRemoveText(rp_label);
   vlfGuiRemoveText(signin);
   vlfGuiRemoveInputBox(username);
   vlfGuiRemoveInputBox(password);
   vlfGuiRemoveCheckBox(rp);
   
   // Construct new items
   vlfGuiCustomBottomDialog(NULL, "Salir", 1, 0, VLF_DEFAULT, OnExit);
   
   vlfGuiGetInputBoxText(password, config.password);
         
         if (config.password[400])
         {
            prueba = vlfGuiAddText(240, 135, "Funcionan");
            vlfGuiSetTextAlignment(prueba, VLF_ALIGNMENT_CENTER);
         }

   vlfGuiSetRectangleFade(0, VLF_TITLEBAR_HEIGHT, 480, 272-VLF_TITLEBAR_HEIGHT, VLF_FADE_MODE_IN, VLF_FADE_SPEED_SUPER_FAST, 0, OnSaveConfig, param, 0);
}


Ahora... yo lo que quiero es hacer esto:
Spoiler:

Código: Seleccionar todo

void OnLoginFadeOutComplete(void *param)
{
   // Destruct old items
   vlfGuiCancelBottomDialog();
   vlfGuiRemoveText(username_label);
   vlfGuiRemoveText(password_label);
   vlfGuiRemoveText(rp_label);
   vlfGuiRemoveText(signin);
   vlfGuiRemoveInputBox(username);
   vlfGuiRemoveInputBox(password);
   vlfGuiRemoveCheckBox(rp);
   
   // Construct new items
   vlfGuiCustomBottomDialog(NULL, "Salir", 1, 0, VLF_DEFAULT, OnExit);

          vlfGuiGetInputBoxText(username, config.username);
         
         if (config.username[40A])
         {
            prueba = vlfGuiAddText(240, 135, "No funcionaria");
            vlfGuiSetTextAlignment(prueba, VLF_ALIGNMENT_CENTER);
         }
   
   vlfGuiGetInputBoxText(password, config.password);
         
         if (config.password[400])
         {
            prueba = vlfGuiAddText(240, 135, "Funciona");
            vlfGuiSetTextAlignment(prueba, VLF_ALIGNMENT_CENTER);
         }

   vlfGuiSetRectangleFade(0, VLF_TITLEBAR_HEIGHT, 480, 272-VLF_TITLEBAR_HEIGHT, VLF_FADE_MODE_IN, VLF_FADE_SPEED_SUPER_FAST, 0, OnSaveConfig, param, 0);
}
Imagen

Avatar de Usuario
m0skit0
Administrador
Administrador
Mensajes: 5585
Registrado: 03 Sep 2009, 09:35
Ubicación: 0xdeadbeef

Re: Problema al hacer un if....

Mensaje por m0skit0 »

Dark_Miguel escribió:if (config.password[400])

Esto no tiene ni pies ni cabeza... Weno me rindo, a ver si alguien te hace entender.
Imagen

Avatar de Usuario
Dark_Miguel
Desarrollador
Desarrollador
Mensajes: 63
Registrado: 12 May 2010, 22:26
PSN ID: Ninguna, pronto me creo una....
Ubicación: Spain, Andalucía. Jaén
Contactar:

Re: Problema al hacer un if....

Mensaje por Dark_Miguel »

m0skit0 escribió:
Dark_Miguel escribió:if (config.password[400])

Esto no tiene ni pies ni cabeza... Weno me rindo, a ver si alguien te hace entender.


Pues ahora me funciona...
Imagen

Avatar de Usuario
m0skit0
Administrador
Administrador
Mensajes: 5585
Registrado: 03 Sep 2009, 09:35
Ubicación: 0xdeadbeef

Re: Problema al hacer un if....

Mensaje por m0skit0 »

Existe una diferencia entre "funcionar" y "estar bien". ¿Cómo le pones un índice 400 si el array sólo tiene 32? Estás comprobando memoria que no pertenece al array, por eso está MAL. Deberías coger y leerte un buen libro sobre programación en C y luego empezar a programar...
Imagen

Responder