Liberty BASIC Community Forum
« Keybord Stuff »

Welcome Guest. Please Login or Register.
Feb 22nd, 2018, 12:19pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: Keybord Stuff  (Read 3763 times)
Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14923
xx Re: Keybord Stuff
« Reply #30 on: Feb 11th, 2003, 06:45am »

on Feb 11th, 2003, 06:05am, steven6446 wrote:
Well i looked at arrays and they do my head in so i gave up with them, i still ent sure what purpose the could be used for in a game but ive managed to make this sonic game without one array, its a crazy looking source code, you would probly laugh at it :-[


We would certainly not laugh at your code!

Here is one way to use an array in a game. Maybe it will give you some ideas for tightening your code or making some things easier.

Here's one way to check the x location of 10 guys on the board:
Code:
'check x location of guy1:
print #game, "spritexy? Guy1 x y"
'if it is too large, reset x:
if x > 300 then x=0
'give guy new location
print #game, "spritexy Guy1 ";x;" ";y

'check x location of other guys the same way:
print #game, "spritexy? Guy2 x y"
if x > 300 then x=0
print #game, "spritexy Guy2 ";x;" ";y

print #game, "spritexy? Guy3 x y"
if x > 300 then x=0
print #game, "spritexy Guy3";x;" ";y

print #game, "spritexy? Guy4 x y"
if x > 300 then x=0
print #game, "spritexy Guy4 ";x;" ";y

print #game, "spritexy? Guy5 x y"
if x > 300 then x=0
print #game, "spritexy Guy5 ";x;" ";y

print #game, "spritexy? Guy6 x y"
if x > 300 then x=0
print #game, "spritexy Guy6 ";x;" ";y

print #game, "spritexy? Guy7 x y"
if x > 300 then x=0
print #game, "spritexy Guy7 ";x;" ";y

print #game, "spritexy? Guy8 x y"
if x > 300 then x=0
print #game, "spritexy Guy8";x;" ";y

print #game, "spritexy? Guy9 x y"
if x > 300 then x=0
print #game, "spritexy Guy9 ";x;" ";y

print #game, "spritexy? Guy10 x y"
if x > 300 then x=0
print #game, "spritexy Guy10 ";x;" ";y

 


You could do the same thing if the "guys" were in an array called "guy" that had two dimensions. The first dimension could hold the sprite index, and the second dimension could hold the x and y values.

dim guy(10,2) '10 guys, each with 2 pieces of info

Now, in your game, to check all 10 in one routine:

Code:

for j = 1 to 10
    print #game, "spritexy? ";guy(j,1);" x y"
        if x > 300 then x=0
    print #game, "spritexy ";guy(j,1);" ";x;" ";y
next

 


The first time through, j = 1, so it will check and reset the first guy sprite. The second time through it will do the second guy sprite and so on. It is much faster and easier to write and understand code this way, once you get the hang of arrays.

Alyce

Also, if you are an unregistered user, you can write larger programs, sicne you fit more info into fewer lines of code... as a way of evaluating LB with a hope to purchase it soon, or course.
« Last Edit: Feb 11th, 2003, 06:53am by Alyce Watson » User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
steven6446
New Member
Image


member is offline

Avatar




PM


Posts: 3
xx Re: Keybord Stuff
« Reply #31 on: Feb 11th, 2003, 1:43pm »

the arrays look interesting and i might be able to use them a bit eventually smiley
User IP Logged

Alyce Watson
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Female
Posts: 14923
xx Re: Keybord Stuff
« Reply #32 on: Feb 11th, 2003, 8:45pm »

on Feb 11th, 2003, 1:43pm, steven6446 wrote:
the arrays look interesting and i might be able to use them a bit eventually smiley


You'll definitely want to learn arrays. They make so many things easier. Look at the week two tutorial in the LB helpfile for instructions on using arrays.

Alyce

( My ebook also has a tutorial on arrays, and one on arrays and looping in the "fundamentals" section of the tutorials area.)
User IP Logged

Alyce
Liberty BASIC Workshop - a complete IDE for Liberty BASIC


Alyce's Restaurant
for Liberty BASIC code, tools and references
kaalidor
Team Liberty BASIC


member is offline

Avatar



ICQ
Homepage PM

Gender: Male
Posts: 458
xx Re: Keybord Stuff
« Reply #33 on: Mar 1st, 2003, 7:10pm »

Hi,
it doesn't work with NT 4 sorry,...... grin
User IP Logged

Have a look to LBasicFr (LB for French Users).
Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls