Jump to content

Photo

Same type of variable but two results differents !


6 replies to this topic

#1 FredTheFred OFFLINE  

FredTheFred

    Space Invader

  • 46 posts
  • Location:Lyon (In France)

Posted Wed Aug 19, 2015 11:45 AM

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
} 
 

 



#2 Pixelboy OFFLINE  

Pixelboy

    Quadrunner

  • 8,242 posts
  • Location:Montreal, Canada

Posted Wed Aug 19, 2015 11:53 AM

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));".

#3 youki OFFLINE  

youki

    River Patroller

  • 2,457 posts

Posted Wed Aug 19, 2015 12:13 PM

if you write :

 

put_at(21,0,str(potion),5);

 

instead of

 

put_at(21,0,str(potion),1);

 

I think you will see your potion increase.

 

You can try also :

 

put_at(21,0,str(potion)+4,1);



#4 BadHornet OFFLINE  

BadHornet

    Dragonstomper

  • 832 posts
  • Location:Smack dab in the middle of Texas

Posted Wed Aug 19, 2015 12:17 PM

1


#5 Kiwi OFFLINE  

Kiwi

    Stargunner

  • 1,693 posts

Posted Wed Aug 19, 2015 12:34 PM

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. 



#6 Pixelboy OFFLINE  

Pixelboy

    Quadrunner

  • 8,242 posts
  • Location:Montreal, Canada

Posted Wed Aug 19, 2015 12:38 PM

Or you can just use print_at(x, y, str(value)), like I stated above.

#7 youki OFFLINE  

youki

    River Patroller

  • 2,457 posts

Posted Wed Aug 19, 2015 1:46 PM

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);






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users