Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Easy way to declare a large amount of variables as 'floats' ?

Author
Message
Mark Garrett
Reviewed AGK on Steam
18
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 21st Nov 2018 12:13 Edited at: 22nd Nov 2018 10:23
I mostly use floats in my programs, and I wondered:

Let's say I have 20 variables and I want to declare them all as 'floats'.

instead of coding:


Is there a way to group them all together and declare them all at once 'as float' , using the designation 'as float' just once ?
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 24th Nov 2018 02:54 Edited at: 24th Nov 2018 02:55
xyx#

The # identifies it as a float.

Just as an FYI, $ identifies the variable as a string.
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 24th Nov 2018 03:48
Sort of, but if you use the symbols, you have to always remember to use the symbol and missing one can be a pain to debug.

x# = 1.0
x$ = "one"
Print(x)
Print(x#)
Print(x$)

Anytime you forget the symbol you will be referring to an integer variable.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 7th Dec 2018 01:51
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 7th Dec 2018 02:43
in some cases, readability.

force as float
velocity as float
mass as float
gravity as float
size as float

force = mass * velocity

is easier to work with than

phys as float[4]

phys[0] = phys[2] * phys[1]
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Vladimuffin
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location:
Posted: 29th Dec 2018 19:07
If you need separate labels for the easy of readability, I'd say writing 20 lines to declare individually labelled floats doesn't seem like too much work. Have you tried making a few arrays to tidy up?



It seems just as simple to remember var[3] as var3. And it makes for easier work down the road with for and if statements.
One smart fellow, he felt smart. Two smart fellows, both felt smart. Three smart fellows all felt smart...

Login to post a reply

Server time is: 2024-04-23 11:30:23
Your offset time is: 2024-04-23 11:30:23