Jump to content
IGNORED

Same type of variable but two results differents !


FredTheFred

Recommended Posts

Hello all,

 

I've got another problem, a strange problem. I use two variables. The first for a score and the second for some potion. There are identical by the type. But score can increase and potion stay to 0...

 

What's wrong ?

 

/* DEFINIE VARIABLES HERE */
unsigned int score;
unsigned int potion;

...

/*POTION*/
void findpotion()
{
cls (); // Clear Screen
show_score();
center_string (3,"YOU FIND A POTION");
center_string (17,"YOU WIN 200 pts");
center_string (23,"PRESS FIRE");
delay (50);
pause();
score = score + 200;
potion = potion + 1;
engine();
}

...

/* SHOW SCORE & POTION*/
void show_score()
{
print_at(0,0,"Score"); put_at(6,0,str(score),5);
print_at(14,0,"Potion"); put_at(21,0,str(potion),1);
}
...

void main()
{
/* DEFINE SCREEN MODE */
screen_mode_2_text(); // DEFINE SCREEN MODE
fill_vram0(0x2000,0x1800,0xf0);
/* DEFINE ASCII TEXT */
upload_default_ascii(NORMAL);
duplicate_pattern();
/* ASSIGNATION POTION 1 IN BEGINNING GAME */
potion =1;
/* START NEXT FUNCTION HERE */
splashscreen (); // CALL SPLASHSCREEN FUNCTION
} 

 

Link to comment
Share on other sites

You forgot to include the splashscreen() function in your posted code.

 

But anyway, I think I see your problem: The last parameter of put_at() is the byte size of the string, and you're passing weird values for that parameter in your code. You should use "print_at(6,0,str(score));" and "print_at(21,0,str(potion));".

Link to comment
Share on other sites

put_at(21,0,str(potion),1); will only print 0. Because the full string is 00001, and it only going to print 1 character. If he have it put_at(21,0,str(potion),5); then it'll show 00001 potion.

If you want a single digit to print for your potion, then put_char(x,y,potion+48); will work 0-9. It points at the tileset.

Double digit needs a MOD of 10 and division of 10 to a temporary variable and then 2 put_char() side by side to show double digit.

Link to comment
Share on other sites

put_at(21,0,str(potion),1); will only print 0. Because the full string is 00001, and it only going to print 1 character. If he have it put_at(21,0,str(potion),5); then it'll show 00001 potion.

 

If you want a single digit to print for your potion, then put_char(x,y,potion+48); will work 0-9. It points at the tileset.

Double digit needs a MOD of 10 and division of 10 to a temporary variable and then 2 put_char() side by side to show double digit.

 

For double digit, i think you can do also simply that :

 

put_at(21,0,str(potion)+3,2);

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...