lucasyuhyuh
Moldy Popcorn
Piece of bacon programming MegaDrive games.
Posts: 47
|
Post by lucasyuhyuh on Nov 14, 2019 11:19:39 GMT -5
How do i put a decimal number (like 0.2 or 36.9) in a integer?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 14, 2019 13:09:39 GMT -5
You can’t.
Please look up why integers can’t have precision. If you can’t find the answer, report back and I’ll explain why.
I’ll give you a hint - it’s not mega drive related (however, it still can’t do precision)
|
|
lucasyuhyuh
Moldy Popcorn
Piece of bacon programming MegaDrive games.
Posts: 47
|
Post by lucasyuhyuh on Nov 14, 2019 14:15:36 GMT -5
I can't find why. Explain it to me please.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 14, 2019 16:17:44 GMT -5
The reason is in the name itself. An integer is any real, whole number. en.wikipedia.org/wiki/IntegerA whole, real number is anything on the number line that isn't a fraction, complex, imaginary, or irrational number. BEX and SecondBASIC both use 16 bit unsigned integers. That means you can't return a negative number, only positive. 16 bit unsigned means the value range can only be between 0 and 65,535. If they were signed integers, the new min-max would be shifted to -32,767 to 32,767. Now, you can still assign negative numbers (the Mega Drive does support signed variables, just BEX and SecondBASIC don't utilize them, and I'm not 100% convinced it's required, though would be useful... *ahem*). If you do this: a = -1 Print a
you'll get an output of 65535. If you absolutely need to display a negative number, you can do something like the following: a = -8 b = 65535-a+1 Print "-";b
Long integers work the same way as integers, except they're twice as big (32 bits) which gives you a value range from 0 to 4,294,967,295. You can assign an integer value to a long integer variable (because it has enough space for it, though it needs to be 0'd out so no left over data is in the memory range), but you can't fit a long integer into a regular integer. Hope that helps. What did you want to do with precision?
|
|
lucasyuhyuh
Moldy Popcorn
Piece of bacon programming MegaDrive games.
Posts: 47
|
Post by lucasyuhyuh on Nov 14, 2019 18:59:28 GMT -5
Just to make some sprites scroll slowly that can make a 2.5D-like illusion.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Nov 14, 2019 19:17:05 GMT -5
This might help:
For x = 0 To 63 DrawTile 1,x,0 DrawTile 2,x,1 Next SetScrollMode HScroll_Cell, VScroll_OverAll While 1 counter++ If counter % 2 = 0 Then Scroll Right,1,0 End If Scroll Left,1,1 Sleep 1 Wend
|
|