English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 15 March 2017, 02:34   #1
Retro1234
Boo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 4,912
Variables?

a=0
My_var=0

Start:
a=a+1
My_var=My_var+1

print a/16
print My_var/16

Goto Start

"My_var" has a decimal point and "a" doesn't why?
Retro1234 is offline  
Old 15 March 2017, 09:20   #2
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,014
Because variable names are case sensitive and you haven't paid attention.
idrougge is offline  
Old 15 March 2017, 09:56   #3
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,347
Blitz has a number of different variable types, some support floating point values (decimal points), some don't. By default variables are the "Quick" type which support decimal points, but if a variable has previously been defined as an integer type it can't be used for floats after.

You can force a variable to be whatever type you like by giving it an extension when you first define it:

a.l makes a long integer (32-bit)
a.w makes a word integer (16-bit)
a.b makes a byte integer (8-bit)
a.q makes a quick float (16-bit integer, 16-bit fractional)
a.f makes a float (32-bit)

These types reflect the standard variable types supported by the system, so you can always choose the most appropriate type for a particular use.

What other code is in your program? As idrougge suggests, if you've previously defined My_var as an integer with different capitalisation, the new version above will be a quick type, which has a decimal point.
Daedalus is online now  
Old 15 March 2017, 10:08   #4
Retro1234
Boo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 4,912
Quote:
Originally Posted by Daedalus View Post
Blitz has a number of different variable types, some support floating point values (decimal points), some don't. By default variables are the "Quick" type which support decimal points, but if a variable has previously been defined as an integer type it can't be used for floats after.

You can force a variable to be whatever type you like by giving it an extension when you first define it:

a.l makes a long integer (32-bit)
a.w makes a word integer (16-bit)
a.b makes a byte integer (8-bit)
a.q makes a quick float (16-bit integer, 16-bit fractional)
a.f makes a float (32-bit)

These types reflect the standard variable types supported by the system, so you can always choose the most appropriate type for a particular use.

What other code is in your program? As idrougge suggests, if you've previously defined My_var as an integer with different capitalisation, the new version above will be a quick type, which has a decimal point.
Yes Thanks My_var.l seems to work

Is there a way I can set all variables to this without adding .l to all my variables?
Retro1234 is offline  
Old 15 March 2017, 10:16   #5
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,347
Yep, the Deftype command does this for all variables declared after the command:

DEFTYPE .l

Bear in mind that smaller types are generally faster to work with, so if you don't need 32-bit numbers, a default of .w might be a better choice.
Daedalus is online now  
Old 15 March 2017, 10:17   #6
Retro1234
Boo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 4,912
My Hero you sir are a legend
Retro1234 is offline  
Old 15 March 2017, 11:25   #7
Retro1234
Boo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 4,912
OK the simple corkscrew is working just again a cut and paste from Amos but a few times ive noticed some weirdness with Variables - ive had to break them right down print them out and then reintroduce them for then to work and I dont think this is my imagination the code is the same????
Retro1234 is offline  
Old 15 March 2017, 11:31   #8
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,347
What do you mean? An intermittent issue? Can you post the problematic code?
Daedalus is online now  
Old 15 March 2017, 11:45   #9
Retro1234
Boo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 4,912
Its gone but basically ive got error about the variable not being right so ive taken out Blit commands etc and parts of the equations and print the results on screen then built it back up again reintroducing the equations and it works???? maybe its to do with the import of the ASCII I dont know but I wasted half hour just breaking it down like this for the code to be the same.

As usual ill upload Amos and Blitz executables later.
Retro1234 is offline  
Old 15 March 2017, 12:19   #10
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,347
When you say "not being right", do you mean "mismatched types", "can't convert types" or similar? If so, this is down to the same issue as above. Blitz variable types need to be thought about more carefully than in AMOS; in that way Blitz is closer to C than BASIC. Often Blitz can convert automatically, but sometimes that doesn't make sense so you need to do it yourself.

AmiBlitz adds an extra compiler directive that allows you to adjust how strict the compiler is about variable types. This helps a lot, since you can set it to give you an error if you don't explicitly declare a variable type.
Daedalus is online now  
Old 15 March 2017, 12:24   #11
Retro1234
Boo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 4,912
The variable calculation have simply not been right - the code is part of a larger 8 way scroll and there are many calculations because you dont just blit the tiles at the edges for this.

The code is the same as Amos and to be honest Blitz isnt so different to Amos - except the terrible manual lol
Retro1234 is offline  
Old 15 March 2017, 12:39   #12
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 5,347
Okay, so it sounds like there's some issue between variable types or the order of the calculation, which is often a source of problems when switching between dialects (and sometimes even just compilers). If one always uses a float intermediate while the other uses an intermediate of the same type as the result variable, you will often get a different result when doing proportional calculation for example.
Daedalus is online now  
Old 15 March 2017, 12:41   #13
Retro1234
Boo

Retro1234's Avatar
 
Join Date: Jun 2006
Location: 5150
Posts: 4,912
Again Thank you for your help and patience
Retro1234 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
[REQUEST] implement Windows variables paths hexaae support.WinUAE 4 28 June 2016 21:40
Cant use system variables in drive paths? Interceptor support.WinUAE 5 26 April 2010 14:50

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:28.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Page generated in 0.08494 seconds with 13 queries