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 DBPro Corner / stretch sprite

Author
Message
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 17th Mar 2008 16:13
hey there, I am unclear about something:

1) when I use STRETCH SPRITE like this: stretch sprite 1,50,50 everything works fine, but if I declare the variable STRETCHING = 50 and use the command like this: stretch sprite 1,stretching,stretching, the sprite won't stretch
2) if I have 2 subroutines which are placed one after the other and none of them ends with the RETURN command, if I call the first one, after it terminates, is it normal to read the second SUB even if I didn't call it or should it terminate the program ( both are placed at the end of the project file so I figure that after an EXIT command from the first sub, the program should exit, while instead, it goes to the second loop )

Could you help me treat my injured Dino-Fly ?
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 17th Mar 2008 16:32
1) Not sure. It should work.
2) The exit command doesnt exit the program it exits the loop. Therfore going to the next loop. If you want to exit the program use the end command.
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 17th Mar 2008 16:36
2) hmm but the exit command should exit the loop and after the loop, there is nothing except the second SUB which should not be executed (I didn't call it), right ??? so I figure that should be the end of the code ...

Could you help me treat my injured Dino-Fly ?
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 17th Mar 2008 17:49
another question, to be more precise ... if I have a sub ( labeled of course ) inside my main loop, is it executed or skipped if I don't call it at all ... here's an example:

DO
etc etc
label;
subprogram for the label
` please note there is no RETURN command
etc etc
LOOP

and another one: how can I end a subprogram if I don't call the RETURN command ??? say I have this:

label1;
etc etc
label2;
etc etc

so you see the subprograms are one after another, yet not closed ... does this mean that label2 is executed in label1 ???

Could you help me treat my injured Dino-Fly ?
Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 17th Mar 2008 21:37
hey thanks for that !!! also, I know what the help files say but please make me understand what's the main difference between GOTO and GOSUB ... I appreciate it

Could you help me treat my injured Dino-Fly ?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 17th Mar 2008 22:21
Quote: "please make me understand what's the main difference between GOTO and GOSUB"


See tutorial 2 here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

TDK_Man

Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 18th Mar 2008 13:45
hmmm I didn't see the GOSUB help ... just the GOTO one ... also, are labels supposed to end with ":" ??? cause I end them with ";" and it works ... why ???

Could you help me treat my injured Dino-Fly ?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Mar 2008 15:41
GOSUB is paired with RETURN. You use GOSUB to jump to a new place in the code, and it remembers where you jumped from. When it hits the RETURN, it jumps back.

GOTO jumps to a new place in the code, but doesn't remember where it jumped from.

It's actually all in TDK's tutorial 2 - just search for GOTO and GOSUB in the tutorial text.

Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 18th Mar 2008 19:39
ah, so I thought myself but why did TDK use ":" for the labels while I use ";" and it still works ??? please help me figure this out

Could you help me treat my injured Dino-Fly ?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 19th Mar 2008 00:23 Edited at: 19th Mar 2008 00:27
To be honest, it's just DBPro being too forgiving.

It should throw up an error if you end a label with a semi-colon instead of a colon - but it doesn't. But even though it works in DBP, it's still wrong to end a label with a semi-colon and you shouldn't really do it.

Likewise, multi-statement lines should also be separated with a colon and even if semi-colons work for that too in DBPro it's still not a good enough reason to use them.

It's just good (and standard) programming practice. It also means you would also have no problems if you switched to another programming language where the syntax is more strictly enforced.

The semi-colon is meant for use with the Print command and disables the Line Feed/Carriage Return - in other words, stops the cursor dropping down to the start of the next line.

So using:

Print "Hello ";
Print "World"


.. the semi-colon on the end of the first print statement results in the word World being printed after the word Hello on the same line.

TDK_Man

Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 19th Mar 2008 14:48
WOW !!! such a helpful post !!! Thanks TDK !!! also, I have another question about multi-statements lines ... so if I have this:

IF a>b THEN print "do": "print "you": print "read": print "this?"

is the IF-THEN command going to treat all 4 PRINTs as a single command or is the multi-statement line helpful just for organizing your code ???

Could you help me treat my injured Dino-Fly ?
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 20th Mar 2008 11:05
In the example you posted, then ALL the Print statements would be executed only if a was greater than b. If a equalled b or was smaller then none of them would.

On multi-statement lines after an If..Then, the additional statements are treated as if they were inside an standard If..Then block:



I only tend to use multi-statement lines too keep complete blocks of code on the screen.

For example, a procedure or function might be 50 or 60 lines long but only 30 when using multi-statement lines - in which case you can see it all on-screen at the same time without having to scroll up and down all the time.

TDK_Man

Twinsen
18
Years of Service
User Offline
Joined: 20th Jun 2006
Location: Romania
Posted: 20th Mar 2008 14:08
aha ... so this method treats all the line as a single block thanks a lot TDK !!! can you please check my LOAD OBJECT thread too ??? it's in the same forum as this one

Could you help me treat my injured Dino-Fly ?

Login to post a reply

Server time is: 2024-11-25 05:33:29
Your offset time is: 2024-11-25 05:33:29