 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
victorprosa
Joined: 14 Jan 2009 Posts: 38
|
Posted: Sat Jan 02, 2010 4:44 pm Post subject: VLF bugged? |
|
|
Hi all!
I've been working with VLF lib for a long time, and i have a lot of experience with it. I am creating an interface for a new homebrew of mine...
This is the first time that I create a mult-lang HB, then, i decided to use RCO importing, which is working like a charm...
But today, I remembered to create the error handler in case of not finding my custom RCO...
Then, I wrote this down:
| Code: | | #include <psputility.h> |
| Code: |
int lang;
lang = vlfGuiGetLanguage();
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_JAPANESE))
{
resources_error = "Unable to load resources!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH))
{
resources_error = "Unable to load resources!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_FRENCH))
{
resources_error = "Impossible de charger des ressources!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_SPANISH))
{
resources_error = "No se puede cargar los recursos!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_GERMAN))
{
resources_error = "Nicht in der Lage, Ressourcen zu laden!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_ITALIAN))
{
resources_error = "Impossibile caricare le risorse!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_DUTCH))
{
resources_error = "Kan middelen laden!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_PORTUGUESE))
{
resources_error = "Nao e possível carregar os recursos!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_RUSSIAN))
{
resources_error = "Unable to load resources!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_KOREAN))
{
resources_error = "Unable to load resources!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_CHINESE_TRADITIONAL))
{
resources_error = "Unable to load resources!";
resource_error_handler();
}
else {
if ((lang = PSP_SYSTEMPARAM_LANGUAGE_CHINESE_SIMPLIFIED))
{
resources_error = "Unable to load resources!";
resource_error_handler();
}
}}}}}}}}}}} |
| Code: | int resource_error_handler()
{
int err;
err = vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
if ((err = VLF_MD_BACK))
{
sceKernelExitGame();
}
return 0;
} |
It seemed to be fine!
As soon as the documents of the VLF Lib tells that vlfGuiGetLanguage(); must return the language...
But, for some strange reason, it is choosing the 2nd option all the time! No matter of what language it is, it does not identifies the PSP language and uses the message writen in the second option...
The only way to avoid this is giving an invalid lang ID as 1st option, in this case this option is choosed by the system...
Is anything wrong with my code?
Is anything wrong with the VLF lib?
Is there any solution/workaround?
PS: Tested in PSP 3000 with GEN-C (which also gives me that annoying "black-waves" bug...) |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Sat Jan 02, 2010 9:51 pm Post subject: |
|
|
Take a closer look at your if statements:
| Code: |
(lang = PSP_SYSTEMPARAM_LANGUAGE_JAPANESE)
|
You don't do comparisons, but assignments there. A common mistake, that can be avoided by writing like this:
| Code: |
(PSP_SYSTEMPARAM_LANGUAGE_JAPANESE == lang)
|
If you ever forget to put the double = there, the compiler will yell at you with a compile time error, because you cannot assign to a constant value.
PS: For easier reading of the code, I recommend you just use a switch statement for the language checks. There are too many curly brackets in that code and the neverending list of closing brackets at the end just looks... strange. This way you also avoid the assignment problem in the check. _________________ <Don't push the river, it flows.>
http://wordpress.fx-world.org - my devblog
http://wiki.fx-world.org - VFPU documentation wiki
Alexander Berl |
|
| Back to top |
|
 |
Davee
Joined: 22 Jun 2009 Posts: 59
|
Posted: Sat Jan 02, 2010 10:54 pm Post subject: |
|
|
| Raphael wrote: | Take a closer look at your if statements:
| Code: |
(lang = PSP_SYSTEMPARAM_LANGUAGE_JAPANESE)
|
You don't do comparisons, but assignments there. A common mistake, that can be avoided by writing like this:
| Code: |
(PSP_SYSTEMPARAM_LANGUAGE_JAPANESE == lang)
|
If you ever forget to put the double = there, the compiler will yell at you with a compile time error, because you cannot assign to a constant value.
PS: For easier reading of the code, I recommend you just use a switch statement for the language checks. There are too many curly brackets in that code and the neverending list of closing brackets at the end just looks... strange. This way you also avoid the assignment problem in the check. |
Definately use a switch statement here, you'll also a minor performance boost as it won't need to do all the comparisons (for items in the lower area). |
|
| Back to top |
|
 |
victorprosa
Joined: 14 Jan 2009 Posts: 38
|
Posted: Mon Jan 04, 2010 7:22 am Post subject: |
|
|
OMG, I can't believe that I forgot about the switch functions!
Thanks for your help guys!
Ahn, and the final code (much simpler):
| Code: | int lang;
char *resources_error;
lang = vlfGuiGetLanguage();
switch (lang){
case 0:
resources_error = "Unable to load resources!";
break;
case 1:
resources_error = "Unable to load resources!";
break;
case 2:
resources_error = "Impossible de charger des ressources!";
break;
case 3:
resources_error = "No se puede cargar los recursos!";
break;
case 4:
resources_error = "Nicht in der Lage, Ressourcen zu laden!";
break;
case 5:
resources_error = "Impossibile caricare le risorse!";
break;
case 6:
resources_error = "Kan middelen laden!";
break;
case 7:
resources_error = "Nao e possivel carregar os recursos!";
break;
case 8:
resources_error = "Unable to load resources!";
break;
case 9:
resources_error = "Unable to load resources!";
break;
case 10:
resources_error = "Unable to load resources!";
break;
case 11:
resources_error = "Unable to load resources!";
break;
default:
resources_error = "Unable to load resources!";
}
int err;
err = vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
if ((err = VLF_MD_BACK))
{
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
whistler
Joined: 04 Mar 2008 Posts: 40
|
Posted: Mon Jan 04, 2010 9:34 am Post subject: |
|
|
| victorprosa wrote: |
int err;
err = vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
if ((err = VLF_MD_BACK))
{
sceKernelExitGame();
} [/code] |
once again, check your if statements |
|
| Back to top |
|
 |
victorprosa
Joined: 14 Jan 2009 Posts: 38
|
Posted: Mon Jan 04, 2010 11:03 am Post subject: |
|
|
| whistler wrote: | | victorprosa wrote: |
int err;
err = vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
if ((err = VLF_MD_BACK))
{
sceKernelExitGame();
} [/code] |
once again, check your if statements |
Sorry, if you want me to use
| Code: | | VLF_MD_BACK == lang |
But it don't works, and
does, without any warning at the compiler, block/bug/error at the PSP/PSPLink... |
|
| Back to top |
|
 |
NoEffex
Joined: 27 Nov 2008 Posts: 108
|
Posted: Mon Jan 04, 2010 11:47 am Post subject: |
|
|
| victorprosa wrote: | | whistler wrote: | | victorprosa wrote: |
int err;
err = vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
if ((err = VLF_MD_BACK))
{
sceKernelExitGame();
} [/code] |
once again, check your if statements |
Sorry, if you want me to use
| Code: | | VLF_MD_BACK == lang |
But it don't works, and
does, without any warning at the compiler, block/bug/error at the PSP/PSPLink... |
What
| Code: | if ((err = VLF_MD_BACK))
{
sceKernelExitGame();
} |
Basically does is
| Code: | err = VLF_MD_BACK;
if(err > 0)
{
sceKernelExitGame();
} |
Meaning, it will never change. _________________ Programming with:
Geany + Latest PSPSDK from svn |
|
| Back to top |
|
 |
willow :--)
Joined: 13 Jan 2007 Posts: 126
|
Posted: Mon Jan 04, 2010 1:51 pm Post subject: |
|
|
How about some "Yagni" in your switch ?
| Code: |
switch (lang){
case 2:
resources_error = "Impossible de charger des ressources!";
break;
case 3:
resources_error = "No se puede cargar los recursos!";
break;
case 4:
resources_error = "Nicht in der Lage, Ressourcen zu laden!";
break;
case 5:
resources_error = "Impossibile caricare le risorse!";
break;
case 6:
resources_error = "Kan middelen laden!";
break;
case 7:
resources_error = "Nao e possivel carregar os recursos!";
break;
default:
resources_error = "Unable to load resources!";
}
|
The less code you have, the happier.
Unless you are just waiting for translations in those various cases, of course ;) _________________ Wagic. Play that card game against an AI on your PSP |
|
| Back to top |
|
 |
coyotebean
Joined: 05 Dec 2009 Posts: 26
|
Posted: Mon Jan 04, 2010 3:24 pm Post subject: |
|
|
| victorprosa wrote: |
Sorry, if you want me to use
| Code: | | VLF_MD_BACK == lang |
But it don't works, and
does, without any warning at the compiler, block/bug/error at the PSP/PSPLink... |
Please remember:
Single = is assignment.
Double == is comparison.
Also, if you have many messages, you may consider using resource array to hold the messages of different languages. Then you don't need so many messy switch/if statements and the code will look much nicer. |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
Posted: Tue Jan 05, 2010 1:34 am Post subject: |
|
|
Well, it's not a psp related question but anyway.
Handling return's this way seems to be common :
| Code: |
int err;
err = vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE);
if ( ( err == VLF_MD_BACK ) )
{
sceKernelExitGame();
}
|
Is there a disadvantage to do that in this situation ?
| Code: |
if ( vlfGuiMessageDialog(resources_error, VLF_MD_TYPE_ERROR | VLF_MD_BUTTONS_NONE) == VLF_MD_BACK )
sceKernelExitGame();
|
From what i understand ( and this is where i'd like to know if i understand correctly ), the "int err" check would be only useful if i would like to check "err" to more than one error code ? Or is it useful/recommended to use it even for one check ? |
|
| Back to top |
|
 |
Draan
Joined: 17 Oct 2009 Posts: 55
|
Posted: Tue Jan 05, 2010 7:27 am Post subject: |
|
|
you're wasting 4 bytes of memory here xD
Do as you whish, it doesn't really matter here |
|
| Back to top |
|
 |
victorprosa
Joined: 14 Jan 2009 Posts: 38
|
Posted: Tue Jan 05, 2010 9:47 am Post subject: |
|
|
| willow :--) wrote: | How about some "Yagni" in your switch ?
| Code: |
switch (lang){
case 2:
resources_error = "Impossible de charger des ressources!";
break;
case 3:
resources_error = "No se puede cargar los recursos!";
break;
case 4:
resources_error = "Nicht in der Lage, Ressourcen zu laden!";
break;
case 5:
resources_error = "Impossibile caricare le risorse!";
break;
case 6:
resources_error = "Kan middelen laden!";
break;
case 7:
resources_error = "Nao e possivel carregar os recursos!";
break;
default:
resources_error = "Unable to load resources!";
}
|
The less code you have, the happier.
Unless you are just waiting for translations in those various cases, of course ;) |
In truth, I am trying to find an easy way to write accents and jp/ch/kr/ru characaters, the traditional methods I used in golden times for DOS doesn't seems to work with the PSP...
----------------------------------------------------------------------------
| coyotebean wrote: | | victorprosa wrote: |
Sorry, if you want me to use
| Code: | | VLF_MD_BACK == lang |
But it don't works, and
does, without any warning at the compiler, block/bug/error at the PSP/PSPLink... |
Please remember:
Single = is assignment.
Double == is comparison.
Also, if you have many messages, you may consider using resource array to hold the messages of different languages. Then you don't need so many messy switch/if statements and the code will look much nicer. |
As you can see in the main post, I am using this messy stuff just for the error handler in case of a missing RCO, resource stuff + xml is much easier handled by the VLF and much simpler in multlang...
------------------------------------------------
Anyway, thank you all for your help =] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|