Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i need a way to shorten this piece of code
#1
i need to know the correct method to shorten this piece of code:
Code:
if room = 1 then 10
if room = 2 then 20
if room = 3 then 30
...etc

im sure i can do this with an equation such a if room = x then goto (10 * x)

i just need a method to show that (10 * x) is a line number to be refered to
-p
Reply
#2
The line numbers referred to by GOTO have to be fixed numbers, not variables or expressions. (Some people like to use SELECT CASE in situations like yours, but that won't shorten your code any. But why are you worried about that?)
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#3
i wasnt worried im just lazy hehe i didnt want to have to type a new line for a room everytime i created a new one...hehe no worries thanks :-)
-p
Reply
#4
Hey there, ummm.
Quote:Code:

if room = 1 then 10
if room = 2 then 20
if room = 3 then 30
...etc
so does that mean that you want to go to a certain label if the room is a certain number, right? Okay, I think there might be an easier way to do it, but I think that if you're a beginning programmer you really should just use what methods you got, then advance your methods generally and gradually. I think that maybe someone will help you out but if you want my opinion I think that you should just stick with what you are doing for now, and maybe you'll come up with your own system soon. I might sound lame but hey, it is my experience in this matter....
ovaProgramming.

One night I had a dream where I was breaking balls. The next morning, BALLSBREAKER was born.

Quote: Excellent. Now you can have things without paying for them.

BALLSBREAKER 2
~-_-Status Report-_-~
Engine: 94%
Graphics: 95%
Sound: 100%
A Severe Error has crippled BB2 for the time being... I have to figure it out, but until then you won't see much of it Sad.
-----------------------------
Reply
#5
yep you're right im starting to develop my skills now. I find its easier to write a programme how you can most easilly understand it and then change it afterwards once u can assess it as a whole and shorcuts become more apparent.

im sure there is a way to accomplish this somehow though, just gotta solve it :-D
-p
Reply
#6
You can always do:

Code:
on room goto 10, 20, 30

Thats pretty short.

Dex
Reply
#7
Not a good style of programming, however. But it works.

It is better to have the rooms in a data structure (arrays and such) and use the same code for everyone of them.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#8
I know . . . I was just answering literally. :wink:

Dex
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)