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.

DarkBASIC Professional Discussion / Tetris Attack (may be actually "Puzzle League" instead)

Author
Message
Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 13th Nov 2014 09:40
Hello. I am not really a new programmer here which I started programmed like almost ten years ago... but all I did programmed was mostly RPG games... Which means I am too new to programming the PUZZLE-genre game; in this case, the Puzzle League where you and your opponent can actually clear blocks around to attack each other by crushing the garbage blocks from top until that player suddenly lost within a limited timer for unable to clear the overfilling screen on time.

I know I would not have to ask for your program to be mine but just more like... some advices would be nice to listen and learn as well.

So far, I got blocks been displayed and also had them be able to drop down while below is empty, which is following the gravity rule. Just added the crosshair-boxes to swap which had been succeed...
But one problem, I don't see any error to my writing for clearing any-number (3 to 5, either horizontal and vertical both) matched blocks while to clear blocks had some strange bugs which it should not be happened.

And I didn't write this part yet but is very curious how would I raise them up AND freezing the raising during clearing the blocks?
Actually, I do know how to freezing it... but in raising case, how do I do this columns when I (as human player) and AI are continuing to clear blocks like no problem for, like 30 minutes (fake but you DO imagine how longer could we able to continue that longer though)? I first tried DATA thing but it backfired my brain somewhere easily and then I tried the array (as in "DIM" command) which it totally worked but since I used the array, does it means the Y spot can't be 12 but like, 1000 with full random-to-select blocks to solve this longer-run problem?

If you have any good idea to shorten my writing or making the game become more smooth than my array's acting (they don't move normally, unlike videogames would actually do... my output's acting is like... well, instant-act (I just started work this just today's night, so that's why)), I would be happy to hear and will credit you if needed.

Thank you for reading, reply or not either.

P.S.: I love to play that kind of puzzle-game and want to programming it, so this way I could able to have some fun against my AI (and second player too).
Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 14th Nov 2014 20:51
Oh and if anybody really need to take a look of my programming to see how does it works (not really finished but does look good though), Just let me know and I would copy it here to show you what did I wrote to make it work.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 14th Nov 2014 22:24
A screen shot please?

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 14th Nov 2014 22:56
Okay, sure thing.
Check my attachment. I apologize for lacking the background because I did started it like last night.

First from left - One matched 3-block had been cleared already when start running. I move crosshair up to those pink blocks on near top-left to swap into...
Second from left - ...this which has been corrected to clear...
Next - But when I move down to those 4-blocks, green and blue to swap... Please look closer enough to the red and light-blue blocks both above...
Last from left - not only green and blue 4-blocks had been cleared but also the red and light-blue 3-blocks had cleared which should NOT be done DURING falling down to land those blocks below.

That is the problem for me to figure what to counter and make it not detect during falling. You see what I mean, yes?
And also, I didn't program to raise blocks up to add more blocks yet, so it's like inital-built blocks to start, just for to test, you know?
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 15th Nov 2014 07:21
Your program cleared red hearts and blue triangles correctly on pic. 4. The problem is that program did it while they were falling. You should make a boolean parameter for every block state - "falling" or "standing". And check and clear only those with "standing". And "standing" are those that have not changed height from the previous cycle.

Basically, your field is small so you can have custom dimension (user type), with every parameter (color, state, x, y, etc...) and process whole field every cycle.

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 15th Nov 2014 20:52 Edited at: 15th Nov 2014 20:58
Hello, Mr. Handy.
First of all, I just started to program, so i already know it's small but better than work too much for big size to waste of time when cancel the programming in near future. But I did made some blocks that are bigger than those ones I ripped from sprite-resource site though. Don't worry about the size, I am already working on it. Just need to make a good background screen to build for a singleplayer screen (and multiplayer too) before I do.

Yes, you are right about "clear red hearts and blue triangles" BUT one problem... When dropping down, clear the blocks during drop have to be FORBIDDEN until it's "standing". and yet, red had be cleared during dropping... but I think i just got it fixed by placing the "drop block" function above before "clear block" and added "drop" flag which it negated the clear just fine, still need more runs to test though...

Actually, you just missed my second-from-last paragraph (P.S. does not count) because I already used the dimension array. =/ and also, I want to know how to raise them up. I am not very sure if it's safe to post a youtube link here or not because that video is what I am trying to write a program (not 100% copy, actually)... Is it safe to post? Because I was told to not post the email address in forums though. o.o
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 16th Nov 2014 07:53 Edited at: 16th Nov 2014 08:15
Youtube is safe, use [youtubе] tags [/youtubе]

Quote: "I already used the dimension array."

User type? Like:
block(13).x=1
block(13).y=3
block(13).state="falling"
block(13).colour="red"

Quote: "Don't worry about the size"

I mean amount of array elements to process.

Quote: "by placing the "drop block" function above before "clear block""

Yeah, sometimes 100% correct code is working wrong if some lines are misplaced.

edit:
I don't know how your code is working, here is if I may did it:

1) Process every column, every block to move it down:

if block is on the bottom - mark it standing
if standing block below block - mark block standing
if empty block below it - mark it falling, drop it

2) Process every row, every block to find matches

if match is found - clear blocks, mark that blocks as empty

Drop down (or up):
below block = above block
above block = empty block

So block amount is constant

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 16th Nov 2014 09:27 Edited at: 16th Nov 2014 09:33
Quote: "Youtube is safe, use [youtubе] tags [/youtubе]"


Okay, in that case...
[youtube]https://www.youtube.com/watch?v=mPXi60W0X7Q[/youtube]
If you would notice the players (Note: they are not me neither) start with 6-blocks height at first match, so like... you could think you only have 6 x 6 blocks to start but no no, players can actually raise it up for more blocks at their willing... OR the time tick to rise as if the game would try to get either-player a Game Over soon or later. As left player decided to raise up to max-height just before it hit the declaring-winner-to-opponent which you have 6 more block-heights, right? so... if it keeps up which you can look some battles there, it can be even 6 width x countless-blocks height...

Quote: "Yeah, sometimes 100% correct code is working wrong if some lines are misplaced."

Sadly, yeah I hate when it happens, lol. Well, I think i already took it care but again, I will have to test it often to make sure it goes correct as I planned. =)

Quote: "User type? Like:
block(13).x=1
block(13).y=3
block(13).state="falling"
block(13).colour="red""

Sadly, yes that's what I did used.

I think it's good idea to put my codes in here, to avoid the confusion because there is not any much personal information to hide.
Here you go. Hope it helps to understand how it works more better. Again, like you said, blocks are smaller to see but it's only just the beginning.

Note - Keystate 24 is "O" (as in this puzzle case, confirm-swap) and the others are WASD crosshair-movement.

Block image is attached... but I wonder how can I attach more than one because you would miss a crosshair image here if you would try to test my codes in your programming.

To comment your last part, yeah I already understood and had covered it by Block(X,Y).Dropping# which 0 means stand (as "false drop") and 1 to drop, so... yeah. But thank you.

Hope my code helps you a lot.

P.S.: I know it's illegal to rip and use copyright images, I was only "borrowing" to TEST around, really! Just once I program to find that it's so perfect I would imagine to play, I will then replace to my own designs which is completely unrelated to pokemons though. I love that puzzle game (pokemon puzzle league / challenge), so yeah.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 16th Nov 2014 12:29
Okay, I will take a close look at the code a bit later.

But this I see right now:
X# AS FLOAT is weird, you don't need to use # if you declared it as float. Same with BYTE.

When posting youtube video you only need to insert video ID between tags, yours is https://www.youtube.com/watch?v=mPXi60W0X7Q

So it will be:


Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 16th Nov 2014 21:17
Oh sorry, it's my first time to post a youtube video up in forums like this. So, I only have to get the "the end" one (as in "mPXi60W0X7Q") in between Youtube codes, that's it? Sounds easy from now. Thank you!

Okay, take your time to check. no need to rush even though i am on a little break from it, is still gathering some thoughts about it at moment.

Quote: "X# AS FLOAT is weird, you don't need to use # if you declared it as float. Same with BYTE."

well, yeah but I don't want to instant-done movement, like from very top down to very bottom in just a nanosecond. Like that video, I do like to SEE those blocks fall down in a normal (or half-slow) motion... so like, I will add some new lines about it by using INC Y#, 0.2 until it hit the real-number (without a decimal) which 1 to 2 to 3 to go-on while falling will be between those numbers to move normally instead instant-stand after a nanosecond drop. Watch whole video and you will understand that all of those falling blocks are in motion instead instant which players are able to swap on quick time (like, it give player a chance to swap before too late to avoid end the chain).
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Nov 2014 00:18
No no no



should be



They are floats! Then just



Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 17th Nov 2014 00:57 Edited at: 17th Nov 2014 01:01
lol, oh okay. well that I didn't know... but thanks.
But it's Type command, so should it be like Block(X,Y).Y instead just "Y" in that INC command? o.o

...Can we get back to my main problem? I mean, I thank you for your help to fix my errors but even so, I would like to finish it to programming soon enough, so I could able to continue to improve & develop more stuffs in it. I am pretty stuck to add in as I am just having trouble to add blocks below 12th row to display. After it had been resolved, I could able to move it somewhere to the better spot for singleplayer-mode while adding the background to play as well as resizing the block-sizes to bigger enough to see like you suggested.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Nov 2014 19:07
I am working on the code. I need some time...

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 17th Nov 2014 20:33
Oh okay. I just thought we had been completely distracted to the off-topic problem. sorry. Didn't thought you are actually coding it. =X
Okay. Let me know if you need any help... even though I am the one who posted this problem as I may lack the knowledge of the puzzle coding, lol.

Okay, take your time then. Did you already took care about the crosshair thing? I mean, it's just too simple to create as it's only 2x four corners on each of two boxes and you are done, lol.

I did updated the controls, by the way... but still working on it due to some new bugs about it though.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 17th Nov 2014 20:59 Edited at: 17th Nov 2014 23:13
I started to upgrade your code (feel the open source power!!! LOL)...

a) found a typo: ComboTimeStop
b) code is not flexible
c) because of b) I'll make you a new core code of Pokemon Puzzle Challenge (it is a fun game!!!).

You will get a good starting code template and will be able to make your own cool puzzle game!

Now please wait...

update:

Work in progress, it may take a few days to complete (busy IRL).

Major changes:

Field array has 1 dimension
Filed is dynamic
Blocks has no X or Y
Filed moving up smoothly
A function to make block animation effects (match, drop)

etc...

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 17th Nov 2014 23:50
Quote: "a) found a typo: ComboTimeStop
b) code is not flexible
c) because of b) I'll make you a new core code of Pokemon Puzzle Challenge (it is a fun game!!!)."

A) First of all, it is correct. This will freeze the raising for few seconds when 4+ blocks had been matched OR creating the chain either. That's because I did added it there just because of raising-blocks coding, so... yeah, it's not a typo... in my "dictionary". XD
B & C) Well, I did mentioned how bad I am at Puzzle game to code because it's my first time to do it so, besides the RPG game (it's very simple coding to do after all). But thank you for making it be more much better to accurate closer enough to that puzzle-game I liked to nearly-clone. I will let you know if I find any code of yours for not understanding how does it works... I mean, there ARE still some things that I don't even understand, even I have a DBPro textbook to explain... My brain is half-dumb and yet is still smart to coding around, XP

Okay. I will wait in few days then. I will code something else while waiting.
Thanks for your big help about those major-changes! Hope my help will be much helpful to you in future, in return for my thanks to your help.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 20th Nov 2014 00:35 Edited at: 20th Nov 2014 01:00
Okay. Here is the code. Media attached!!!



@Everybody

Guys, if someone have spare time, please help to improve block logic! I have no time now...

Current flaws:

1) You can switch block 1 and [an empty space] under a falling block 2. Block 2 lands on block 1.
Should be: empty space under the falling block 2 is locked.

2) If you move one block left or right to other two in same row, and there is a gap between, blocks are matched (one block hangs in air).
Should be: block should fall into gap, no match.

3) Blocks in a column are falling separately.
Should be: blocks are falling simultaneously.

4) No animation when block hits the floor
Should be: animation!

5) Possible: some jerking when blocks falling more than one row, because it is falling one row down, then again, and again...
Should be: smooth

edit: 6) Moonwalking! If you are fast, you can shift whole column! Just swap the blocks (with empty space, of course) moving from bottom to top.
Should be: I don't know! LOL

How match working: all matched blocks are tagged as -1 to make possible matched lines intersections; then whole field is passed again to convert all -1 to matched.

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 20th Nov 2014 02:13 Edited at: 20th Nov 2014 02:18
Wow, thanks!

*testing*

some errors when comparing the original... but I can try my best to fix your errors though. Again, big thanks, Mr. Handy!

*scoring 2 3-blocks at same time and the falling blocks just hit the clearing-animation* tsk tsk, that's not correct. XD
I mean, when animating to clear, blocks (the ones that would be about to fall) must be stayed up there until the clear animation has been finished which the falling function can then begin animate to drop down. But I will cover it however.

Just a question; Why are you not using Types? o.o

I will take that you didn't program the raising blocks yet as I did noticed it.

And also, each time I run your program, it's same run as before which you didn't set all of those blocks as random for each run, =O

But thanks! I will make sure to credit you for that while I fix your errors! A star for you! ^.^=<

Hm? Set Window Layout??? *check "Help" function to understand* OMG, that's the command I want to use for my other programs to hide the window-titlebar! O__O Thank you again! XD
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 20th Nov 2014 02:45
Quote: "And also, each time I run your program, it's same run as before"

Look at the randomize

Quote: "must be stayed up there until the clear animation has been finished"

there should be additional parameter in block() to store the timestamp
Yeah, just no left time for it

Quote: "I will take that you didn't program the raising blocks yet as I did noticed it."

Now they rising... sort of! OMG LOL


Quote: "Why are you not using Types?"

block() is a type...

mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 20th Nov 2014 02:59
P.S. My code is not so cool (and with latest feature it just went crazy), it was written from scratch and without any plan, so if you will write a good plan, you will make a good code. The benefit of the plan is to a list of all possible variable you will ever need in your program. I hope this code will give you the idea of block matching engine and using a one-dimensional array. Do not use two-d arrays, they are, as I remember, not dynamic and may be buggy.

P.P.S. I got score 69!

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 20th Nov 2014 05:26 Edited at: 20th Nov 2014 05:34
Quote: "Look at the randomize"

Yeah, I just noticed it after posted. My late-response apology. =P

Quote: "there should be additional parameter in block() to store the timestamp
Yeah, just no left time for it"

Well, I don't care about the time, ROTFL. But thanks. Come to thought, why IS the time required? I mean, if it would take longer than ten minutes ("Tetris Attack" videogame limited that 10 mins (as in 9:59-seconds)), then there is not any point for check Time on display instead check it on after-game calculate-score screen (you know, once the game get over, it brings to the scoring screen, yeah?)? o.o;

Quote: "Now they rising... sort of! OMG LOL"

*checking* Oh I see, lol. yeah, thanks but it's pretty off and could bring player a gameover before they get a chance to check the whole screen, hahaha. But thanks. I will make sure to check and code to fix this "sort-of" error.
Wow, I just found "Start rows" and changed 12 to 6 but when running to test, it didn't got any new block from below while rising. o.o I will see what I can do about it once I finish analyze your codes to understand.

Quote: "block() is a type..."

Oh no, not that one. I mean those ones!
imgnum_, field_, block_, pointer_, and bg_
If you would just create "TYPE Locations" command with X and Y variables, you can link it to those ones that is needed for X and Y instead repeating, don't you think so? I am not actually arguing with you, just wondering why not is all. I mean, we all have different methods to write the code, right?

Again, thank you!
I think I need to make sure to code the random-seed, to make sure player and opponent get no match at start before the "3, 2, 1, start!" countdown or otherwise it would be very unfair, yes?

Oh, hey Mr. Handy, mind to tell me what does "Local" command actually do? Help didn't tell any much information only except this; "For local variables, you can re-enforce the declaration as follows (example)"... that's it. =/

P.S.: Huh? Should X be hortizonal instead vertical? o.o i just noticed your swap-block function that it said x, y, x, y-1... which is more like to swap top-and-bottom instead left-and-right. XD
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 20th Nov 2014 12:16 Edited at: 20th Nov 2014 12:19
Quote: " then there is not any point for check Time on display instead check it on after-game calculate-score screen (you know, once the game get over, it brings to the scoring screen, yeah?)?"

Timestamp should store time (countdown) after block is vanished but should hold an invisible space; this will make your
Quote: "must be stayed up there until the clear animation has been finished"



Quote: "mgnum_, field_, block_, pointer_, and bg_"

Those are variables, not arrays, you will only got . instead of _ that is all the difference.
Quote: "what does "Local" command actually do?"

As I remember, if you have global X but you want to use another X inside function you can make a local X that will be restricted only to that function.


Quote: "Huh? Should X be hortizonal instead vertical? o.o i just noticed your swap-block function that it said x, y, x, y-1... which is more like to swap top-and-bottom instead left-and-right"

Block swap works for both directions. It has direction detection. Look closer.

As you have not got through all the code, [value && 1] is a boolean operation to detect if value odd or even (returns 1 or 0)

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 20th Nov 2014 23:05
Oh okay. I guess so. even though you can use the hidden-countdown instead, lol.

Oh okay. for some reason, in my view, it seem same to me though... oh well.

*testing the Local from your code* oooooh, so like... off-track variable for a quick moment? I see. I kinda get it, even though it would mess my imagining mind up, lol

yes, it's right that we can swap either but in this case, I only want hortionzal one as left-and-right. But thanks though.

I tried my best about that boolean operation but it mostly failed to follow my plans in my other game program. =(
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 21st Nov 2014 16:24


Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 21st Nov 2014 20:37
well, yeah but if you check my other topic (which should be too old by now), I am talking about to detect which evolution should one able to meet many conditions to fulfill... If you do watch or play Digimon, then you should recongize this easily.

Agumon can evolve more than just either Greymon or GeoGreymon ( here, look at "Evolves To" under "Evolution" section; http://dma.wtw-x.net/dexagu.shtml )... but it's too many adults (in USA, Champion) to evolve and could totally mess the evolution conditions, so... if you already played "Digimon World 1" or emulating "Digimon Re-Digitize" either, it would be like this as I was adviced by some guy.
Using boolean operation, as like you said.
So I thought it would be like...
10000000 (met all conditions to fulfill and will evolve THAT adult)
11101001 (listed right below here)
(Greymon)(GeoGreymon)(Angemon)(etc) in each number-digit and only evolve in 1 to detect... but when I tested, it reveal false mostly even I set those variable BE true... In other word, I tried to make Agumon evolve into Greymon but in end, it tells "false" instead, even i did wrote like this
"IF 10000000 = 11101001" or something like that, it returns false. So I am confused about this, even I read the site to explain the whole boolean operation
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 21st Nov 2014 21:58 Edited at: 21st Nov 2014 22:00
You need to convert 000001010110 to string with STR$()

Like this:

state$ = STR$(condition_1) + STR$(condition_2) + STR$(condition_3) + STR$(condition_4)...

Every time you change character's parameter you will need to re-build your state$ again. And then

state$ = requirement$

will work! Because it will be exactly 000001010110 = 000001010110 as you want.

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 22nd Nov 2014 21:50
uh...
in other word, Agumon will evolve into ALL of those possible evolutions at same time instead pick ONLY ONE of them, like pokemon... o.o;; But I guess that may do... I will see what I can do about that someday. Thanks.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 23rd Nov 2014 00:22
No!

First you must check if he meets evolution requirements (01010101010010) for every possible evolution (if different requirements), then make a list (dynamic array) of acceptable evolutions, then use RND(array count()), then pick one and evolve, then watch My Little Pony.

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 23rd Nov 2014 02:00
Rainbow Dash!

I am very sorry for be dumb, TT__TT" I am just trying to be not dumb...

Well, yeah, I was just thinking like this...
if he has more than required ATK, flag it as 1... if his DEF has less than required DEF, flag it as 1... if his Speed is NOT less than required SPD, flag it as 0... so go on... then after that, I total them together to flag a whole 1 or a whole 0 for THAT evolved one...

It will be repeated for the others that can be actually evolved (regardless the evolution-conditions)...

By the way, what's the difference between non-dynamic and dynamic array? o.o;;
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 23rd Nov 2014 02:23
All one-dimensional arrays are dynamic. You can add or remove items. You can remove all items from array or create empty array. Read help topics. Two-and-more-dimensional are not recommended to use at all.

Quote: "I am very sorry for be dumb, TT__TT" I am just trying to be not dumb..."

No you are not, you just posting random conclusions!

Quote: "Well, yeah, I was just thinking like this..."

If your requirements also based on < or > then you should make an array:
requirment(1).min_strength = 50
requirment(1).max_strength = 75
requirment(1).if_true_evolve_to = "charizard"

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 23rd Nov 2014 04:24
I have no idea what 2-and-more-dimensional (that if you don't mean 2D/3D pictures) actually, lol.

Because I was just trying to draw your "dots" to understand... I mean, I sucks to understand though.

Well, yeah, true enough... I will try to do code your advices in future when I get that mood back, Thanks again.
mr Handy
18
Years of Service
User Offline
Joined: 7th Sep 2007
Location: out of TGC
Posted: 23rd Nov 2014 04:40
Quote: "have no idea what 2-and-more-dimensional"


Open editor, press F1:

INTRODUCTION
GETTING STARTED
PRINCIPLES
COMMANDS
EXAMPLES
INDEX
TECHNICAL DOCUMENTS


go to PRINCIPLES:

Datatypes and variables
Operators
Common statements
Functions
Syntax
Lists, stacks and queues
Numerical bases
Errors and warnings
ASCII character codes


go to Datatypes and variables:

There you can read this:

------------------------------------------------------------------------------------------------------------

Data Types, Variables and Arrays


DATA TYPES

We have established that statements are used to write a program. A statement can be broken up into a command and its data. The command is the operation, or task you wish to perform. The data is that which must be used by the command to complete the operation. The data is also referred to as the parameter(s).

There are many types of data you can use, including integer numbers, real numbers and string. Each type of data holds a slightly different type of value.

Integer Numbers

An integer number can hold a whole number, but no fraction. For the value to be negative, you must place a hyphen symbol (-) before the value. You must not use commas as part of the number as this would generate a Syntax Error. Examples of integer numbers:


42
10000
-233000
-100

Real Numbers

A real number can hold a whole number or a fractional number that uses a decimal point. For the value to be negative, you must place a hyphen symbol (-) before the value. Examples of real numbers:


20.0005
99.9
-5000.12
-9999.9991

Strings

String data is non-numerical, and is used to store characters and words. All strings consist of characters enclosed within double quotation marks. The string data can include numbers and other numerical symbols but will be treated as text. Examples of strings are:


"A"
"Hello World"
"Telephone"
"I am 99 years old"
"1.2.3.4.5.6.7.8.9"

Each string can consist of as many characters as the memory allows. You can also have a string with no data whatsoever, represented by an empty pair of double quotation marks.

DATA TYPE RANGES

Each type of data has a maximum and minimum value known as the range. It is important to know these ranges, especially when dealing with smaller datatypes. Below is a list of datatypes and their ranges:


INTEGER Range : –2,147,483,648 to 2,147,483,647
REAL Range : 3.4E +/- 38 (7 digits)
BOOLEAN Range : 0 to 1
BYTE Range : 0 to 255
WORD Range : 0 to 65535
DWORD Range : 0 to 4,294,967,295
DOUBLE INTEGER Range : –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
DOUBLE FLOAT Range : 1.7E +/- 308 (15 digits)

VARIABLES

The best way to demonstrate what a variable does is by way of an example. Take the calculation:


A = 3 + 4

A variable is used to store a value. It"s that simple. You can have a variable that stores any type of data, and you can have as many as you want. The following program shows you how the contents of the variable can be output to the screen:


A = 3 + 4
PRINT A

Now take the next example to show you how variables can be used as freely as standard number types:


A = 2
B = 8
C = A + B
PRINT C

In the preceding example, 3 is stored in the A variable, 4 is stored in the B variable and C is given the result of the calculation between A and B. The calculation is based on the values stored within the variables and so the calculation is actually C = 2 + 8. The result, which in this case is 10, is stored as the new value of C and this is the value that eventually gets printed to the screen.

So far, we have seen variables used to store and recall integer values. Variables can also store real numbers and strings. In order to allow a variable to store these other types of data, you must make sure the variable is recognized as an integer, real or string variable. To name a real number variable, you must add a hash character (#) as the last character of the variable name. If you want your variable to store a string, you must add a dollar character ($) as the last character of the variable name. Let"s see these new variables used to store and recall real values:


mydata#=42.5
PRINT mydata#

By adding the (#) symbol, we are instructing the program to treat the variable as a real number variable. Exactly the same rule applies to a string variable:


myname$="Lee"
PRINT myname$

All variable names can use either upper or lower case characters, which means a variable called NAME$ is the same variable as name$ or Name$. String variables even support the use of limited maths. The following example adds two strings together and the result is a concatenation of the two strings:


a$="Hello"
b$="World"
c$=a$+b$
print c$

To run this example, the text "HelloWorld" will be printed to the screen. Would you be able to alter this example to place a space between "Hello" and "World"?


ARRAYS

Arrays are going to be a very important part of your future programs. They allow you to store large amounts of data under a single name. You can then access the data by index rather than by name alone.

If you had to write a program that stored each weeks lottery numbers, typing out 52 unique variable names is a lot of work, hard to maintain and quite unnecessary. Arrays allow you to create a special kind of variable that can store more than one item of data. You might start your program like this:


lottery1$="43,76,12,34,12,11"
lottery2$="76,12,34,12,11,44"
lottery3$="12,34,12,02,05,07"
etc..

Two hours later, you realize you could have written it like this:


DIM lottery$(52)
lottery$(1)="43,76,12,34,12,11"
lottery$(2)="76,12,34,12,11,44"
lottery$(3)="12,34,12,02,05,07"
etc..

We declare a string array using the DIM command followed by a name for our array. Like variables, when we use a dollar symbol after the name we instruct the program to use the array to store only strings. We then enclose in brackets how many items of data we wish the array to store. The array can be filled almost like a variable, but you must also provide the position within the array you wish to store your data.

But you then ask yourself what benefits I would have gained using the second approach. If you where also required to print out all 52 lottery numbers to the screen with your first approach you would have to add another 52 statements that printed each variable:


PRINT lottery1$
PRINT lottery2$
PRINT lottery3$
etc..

But if you had used an array, the same example would look like this:


PRINT lottery$(1)
PRINT lottery$(2)
PRINT lottery$(3)
etc..

You will have noticed that by using an array, you no longer have to refer to your data using a unique variable name. You can now point to the data you want using a position number. Accessing data this way has a thousand advantages over trying to access data by variable name alone, as you will discover. One example would be to improve the above like this:


FOR T=1 TO 52
PRINT lottery$(T)
NEXT T

Incredibly the above code replaced 52 PRINT statements with just 3 statements. With the above example, T is incremented from 1 to 52 within a loop that prints out the contents of the array at that position.

Arrays can also store multiple levels of data. At the moment our lottery entries are stored as strings and the numbers are hard to get at. Let"s say we wanted to store all six numbers for every lottery week, we would create an array like this:


DIM lottery(52,6)

Without the dollar symbol($), we are declaring the array to store integer numbers instead of strings. You will also notice we have a second number separated by a comma. This means for every array position from 1 to 52, there is a sub-set numbered 1 to 6 in which multiple data can be stored. You can visualize an array as a filing cabinet with large draws numbered 1 to 52. Within each of the 52 draws is a tray with 6 boxes inside. You can store a value in each box. In all you can store 312 (52 x 6) values in this array. You can have up to five dimensions in your array, which means you can create an array as big as (1,2,3,4,5). Be careful when declaring dimensions, as large arrays consume large amounts of memory and may reduce overall performance of your program.

Entering data into our new array is elementary:


lottery(1,1)=43
lottery(1,2)=76
lottery(1,3)=12
lottery(1,4)=34
lottery(1,5)=12
lottery(1,6)=11
lottery(2,1)=43
lottery(2,2)=76
lottery(2,3)=12
lottery(2,4)=34
lottery(2,5)=12
lottery(2,6)=11

You are now able to give your program access to much more useful data. Unlike the string approach, you could make your program count how many times a certain number has appeared.

As you have determined, arrays need to be declared as a particular type. You can have an array of integer numbers, real numbers or strings. You cannot have multiple types in the same array, but you can declare new arrays dedicated to holding such data.

You can also declare arrays as global or local. Global arrays are the ones you are familiar with, and can be accessed by any part of the program. Local arrays can only be accessed by the function in which it was created. It is important to note that the global array must be delcared at the top of the main source code of the program as arrays are dynamically created only when the DIM command is executed. Placing DIM commands at the top of included source code will not dynamically create the array unless it lies within a subroutine called from the main program.

To re-enforce the variable is global, you can declare it as follows:


GLOBAL myglobal AS INTEGER

For local variables, you can re-enforce the declaration as follows


FUNCTION myfunction()
LOCAL mylocal as INTEGER
ENDFUNCTION

USER DEFINED TYPES

If the current set of datatypes is inadequate for your needs, you can can create your own data types using user-defined-type. User defined types are useful for storing data using logical fields rather than the unfriendly list of subscripts used by arrays.

To create a user defined type, you must first declare it at the top of your program. To do so, you would give your type a name and a list of fields it contains:


TYPE MyType
Fieldname1
Fieldname2
Fieldname3
ENDTYPE

The above code creates a type called MyType with three fields contained within it. As the fields have no declaration, they are assumed to be integers. The same code could also be truncated to a single line like so:


TYPE MyType Fieldname1 Fieldname2 Fieldname3 ENDTYPE

To use your type, you simply create a variable and declare it with your new type. To declare a variable as a specific type, you would use the AS statement:


MyVariable AS MyType

You can then assign data to your variable as normal, with the added bonus of the fields you have given your variable like so:


MyVariable.Fieldname1 = 41
MyVariable.Fieldname2 = 42
MyVariable.Fieldname3 = 43

At the moment, the type is assuming our fields are integers. We may wish to declare our fields as a real number, string or other datatype. We can do so using the same AS statement within the type definition. So the following code makes more sense we shall give our type and fields sensible names:


TYPE AccountEntryType
Number AS INTEGER
Name AS STRING
Amount AS FLOAT
ENDTYPE

You can use a type like any other, so creating and using an array of the above is simply a case of declaring the array with your new type:


DIM Accounts(100) AS AccountEntryType
Accounts(1).Number=12345
Accounts(1).Name="Lee"
Accounts(1).Amount=0.42

As you will eventually discover you can have types within types for more complex data structures so we can imagine one of the fields contains more than one value. We would define two user defined types, and then use one of them in the declaration of one of the fields of the section user defined type, as follows:


TYPE AmountsType
CurrentBalance AS FLOAT
SavingsBalance AS FLOAT
CreditCardBalance AS FLOAT
ENDTYPE

TYPE AccountEntryType
Number AS INTEGER
Name AS STRING
Amount AS AmountsType
ENDTYPE

DIM Accounts(100) AS AccountEntryType
Accounts(1).Number=12345
Accounts(1).Name="Lee"
Accounts(1).Amount.CurrentBalance=0.42
Accounts(1).Amount.SavingsBalance=100.0
Accounts(1).Amount.CreditCardBalance=-5000.0

As you can see, user defined types are not only powerful, they make the readability of your programs far easier. Using named fields instead of a subscript value within an array, you can save yourself many hours all for the sake of an incorrect subscript value throwing out your program results.

POINTERS

You can use the value of a variable to specify, read and write the contents of an address by using the "*" indirect symbol. This is useful for obtaining areas of memory you wish to read from or write to and control the pointer into this memory using a standard variable.


Ptr as DWORD
Ptr=Make Memory(4)
*Ptr=42
PRINT *Ptr

The above code simply declares Ptr as a DWORD variable, assigns the variable a created area of memory, writes the value 42 into that location of memory and then reads the same address back, the contents of which is to be printed to the screen. You would never use an absolute address to assign a pointer. There are commands such as GET BACKBUFFER PTR and MAKE MEMORY which return such address values. You can only use a standard variable with indirection, and array and type variables are not valid. This is an advanced feature and as such potentially dangerous. Writing into invalid memory can cause unexpected program behaviour and even crashing. Use caution when employing the indirect symbol.

Pointer based memory access is limited to 32-bit DWORD datatypes only, and does not support advanced pointer concepts such as pointer addition, data type casting or non-32-bit data access. To achieve these concepts, use your own code to manage pointer address values and bitwise commands.

Jachan19
15
Years of Service
User Offline
Joined: 1st May 2011
Location:
Posted: 23rd Nov 2014 08:03
no need to copy the whole because I know where it is, lol.

And to answer your explain, all I can say is just... "okay. o.o; "

Login to post a reply

Server time is: 2026-07-17 12:28:46
Your offset time is: 2026-07-17 12:28:46