GOSUB statement

Hello,Today i will explain what GOSUB means


GOSUB , wiki:

GOSUB is a command in many versions of the BASIC computer programming language. A GOSUB statement jumps to a line elsewhere in the program. That line and the following lines up to a RETURN are used as a simple kind of a subroutine without (sometimes with) parameters or local variables.

ok so here is a simple script:

Code:
{$CLEO}


0000: NOP

:START
wait 0 
if and
056D:   actor $PLAYER_ACTOR defined //check if actor is defined else jump to START to loop again
key_down 49   //if key 1 pressed run the code below , else jump @start again to loop
jf @START
02AB: set_actor $PLAYER_ACTOR immunities BP 1 FP 1 EP 1 CP 1 MP 1 //this will get you full immunitie (god mode)
0AD1: show_formatted_text_highpriority "GOD MODE ACTIVATED " time 2000 0x0AD1
jump @START


now to add the GOSUB thing we change the script to this way:


Code:
{$CLEO}


0000: NOP

:START
wait 0 
if and
056D:   actor $PLAYER_ACTOR defined //check if actor is defined else jump to START to loop again
key_down 49   //if key 1 pressed run the code below , else jump @start again to loop
jf @START
gosub @set_godmode_on
0AD1: show_formatted_text_highpriority "GOD MODE ACTIVATED " time 2000 0x0AD1
jump @START



:set_godmode_on  // i will explain this below 
wait 0     //this is optional , some people don't add wait , but i prefer to add it 
02AB: set_actor PLAYER_ACTOR  immunities BP 1 FP 1 EP 1 CP 1 MP 1 //this will get you full immunitie (god mode)
return //this will return to the loop flow in label START

NOW gosub code is this:

Code:
gosub [member=42621]Sub[/member]  //this should be add in the main script (in our case it is :START)

:sub // i will explain this below 
wait 0     //this is optional , some people don't add wait , but i prefer to add it 
02AB: set_actor PLAYER_ACTOR  immunities BP 1 FP 1 EP 1 CP 1 MP 1 //this will get you full immunitie (god mode)
return //this will return to the loop flow in label START

first of all we add "GOSUB [member=42621]Sub[/member]" in the main script (the label START) , capitals letters don't effect the code.

since GTA read from up to down , first label will be read is ":START" and after it ended it will jump again at start because we added " jump @START" in the end

so ":sub" won't be read unless it got called in the main flow of label "START"


1)so sub is like normal label , start with " : " followed by letters or numbers
2)then we add wait 0 , this is not needed , many scripters don't add wait 0 , but i prefer to add it to avoid further lags ..etc
3) now we added our code that will run when the flow in the main loop reach the gosub [member=42621]Sub[/member] code
4) we always end the subs with return


PS: subs don't get end with "jump @" and not contain"jf @"
instead it always end with "RETURN"


subs are really easy , but you can understand better if you reviewed the codes and how you call the sub and go to it then run the codes under it then return back to where you called the sub and continue the script


subs are usually used for calculating things and/or checking things then back  to the main script , so subs are VERY VERY useful in many ways



here is a SCRIPT that will save then teleport you to the saved position
try to understand it , if you can't or stuck at some point please comment so i can explain it for you
here you go:

Code:
{$CLEO}


0000: NOP


:FIRST
wait 0
if and
056D:   actor $PLAYER_ACTOR defined
0AB0:   key_pressed 50 //2
jf @FIRST
gosub @store_actor_position      //this will call the sub
0AD1: show_formatted_text_highpriority "Your Position SAVED." time 2000 0x0AD1
jump @SECOND

 // in case you ask in the first step we didn't add jf @SECOND , becouse second will put the actor at the coords we got from "FIRST" label
 //so we can put actor in 1@ 2@ 3@ if we jumped to the second label becouse it is not defined , so we have to run through label "FIRST"
 //to store the position , else it will put the actor at 0.0 0.0 0.0 becouse 1@ 2@ 3@ is not defined
:SECOND
wait 0 
if 
0AB0:   key_pressed 51 //3
then
gosub [member=31703]teleport[/member]
0AD1: show_formatted_text_highpriority "You Back to your Position." time 2000 0x0AD1
end
jump @FIRST


:store_actor_position   //our sub
wait 0
00A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 3@
return


:TELEPORT
wait 0
00A1: put_actor $PLAYER_ACTOR at 1@ 2@ 3@
return

what i gave you now in codes is a very little thing that subs cover .
because subs can be used in millions ways ...





thanks for following my tutorials.
if i helped you please hit the thanks button and the little heart(rep.) under my name so you can make me more trusted for users so they can reach me easily.
 

TheZeRots

Expert
Joined
Dec 21, 2013
Messages
1,247
Reaction score
1
Re: 12)GOSUB statement -TUT

1. Why would you use gosub and create entire new label here when you can simply continue that script after else_jump and add whatever you want?

2. Also you didn't mention why we use RETURN and not jump!

3. You also forgot to mention where RETURN command returns the script to!

4. Why did you use gosub here when you could of just used a regular jump?
 

blackHat

Expert
Joined
Jul 28, 2013
Messages
930
Reaction score
2
Re: 12)GOSUB statement -TUT

Mr.Ze link said:
1. Why would you use gosub and create entire new label here when you can simply continue that script after else_jump and add whatever you want?

2. Also you didn't mention why we use RETURN and not jump!

3. You also forgot to mention where RETURN command returns the script to!

4. Why did you use gosub here when you could of just used a regular jump?

all 4 things you mentioned i already said it all ,, learn to read before you read ...

why you always argue without even  understand .
 

Opcode.eXe

Expert
Joined
Feb 18, 2013
Messages
1,486
Reaction score
226
Location
( ͡° ͜ʖ ͡°)
Re: 12)GOSUB statement -TUT

Mr.Ze link said:
1. Why would you use gosub and create entire new label here when you can simply continue that script after else_jump and add whatever you want?

2. Also you didn't mention why we use RETURN and not jump!

3. You also forgot to mention where RETURN command returns the script to!

4. Why did you use gosub here when you could of just used a regular jump?

1.) You can save alot of space and text, also you can type GOSUB @BLA everywhere you want, so you dont have to add that code all the time. If you wanna change something you just have to edit the :sub lines, and not the shit you copy and pasted everywhere.

2.) Why would you use GOSUB then? a gosub needs a return otherwise it wont jump back to the line where you typed GOSUB @.

3.) read 2.) - to jump back to the line where u typed GOSUB @

4.) read 1.)

also Blackhat explained that in dat tutorial
 

blackHat

Expert
Joined
Jul 28, 2013
Messages
930
Reaction score
2
Re: 12)GOSUB statement -TUT

Opcode.eXe link said:
1.) You can save alot of space and text, also you can type GOSUB @BLA everywhere you want, so you dont have to add that code all the time. If you wanna change something you just have to edit the :sub lines, and not the shit you copy and pasted everywhere.

2.) Why would you use GOSUB then? a gosub needs a return otherwise it wont jump back to the line where you typed GOSUB @.

3.) read 2.) - to jump back to the line where u typed GOSUB @

4.) read 1.)

also Blackhat explained that in dat tutorial

thank you bro , i appreciate your backup :)
 

NoJustNo

Active member
Joined
Jul 26, 2014
Messages
178
Reaction score
0
Re: 12)GOSUB statement -TUT

As Allways ,  :urtheman: :urtheman: :yesyes:
 

TheZeRots

Expert
Joined
Dec 21, 2013
Messages
1,247
Reaction score
1
Re: 12)GOSUB statement -TUT

Opcode.eXe link said:
1.) You can save alot of space and text, also you can type GOSUB @BLA everywhere you want, so you dont have to add that code all the time. If you wanna change something you just have to edit the :sub lines, and not the shit you copy and pasted everywhere.

2.) Why would you use GOSUB then? a gosub needs a return otherwise it wont jump back to the line where you typed GOSUB @.

3.) read 2.) - to jump back to the line where u typed GOSUB @

4.) read 1.)

also Blackhat explained that in dat tutorial
I was asking BlackHat on purpose, nice that you shove your head in the backside of a leecher to cover his butthole.
 

blackHat

Expert
Joined
Jul 28, 2013
Messages
930
Reaction score
2
Re: 12)GOSUB statement -TUT

Mr.Ze link said:
I was asking BlackHat on purpose, nice that you shove your head in the backside of a leecher to cover his butthole.
Haters gona hate..
A jealous child  gonna act childish

FraizeR007 link said:
wtf what is this
tutorial
 

TheZeRots

Expert
Joined
Dec 21, 2013
Messages
1,247
Reaction score
1
Re: 12)GOSUB statement -TUT

And also, Opcode, please, you went down so low that you are going to lie just so you can talk against me.

BlackHat showed no purpose to use gosub. After else_jump you could just put in the code, instead of putting gosub and making an entire new label. Saved text? Ha, nope. When you have then multiple nosubs, you're telling me it's easier than just looking at original label? Yeah, sure.

He hasn't explained half you did.
 

Opcode.eXe

Expert
Joined
Feb 18, 2013
Messages
1,486
Reaction score
226
Location
( ͡° ͜ʖ ͡°)
Re: 12)GOSUB statement -TUT

Mr.Ze link said:
And also, Opcode, please, you went down so low that you are going to lie just so you can talk against me.

BlackHat showed no purpose to use gosub. After else_jump you could just put in the code, instead of putting gosub and making an entire new label. Saved text? Ha, nope. When you have then multiple nosubs, you're telling me it's easier than just looking at original label? Yeah, sure.

He hasn't explained half you did.

Everyone know's you hate Blackhat, you're asking him questions that he 'probably' can't answer on purpose. I just helped him. He's making tutorials and you're like a little bug that is trying to get into his asscrack...
 

blackHat

Expert
Joined
Jul 28, 2013
Messages
930
Reaction score
2
Re: 12)GOSUB statement -TUT

Opcode.eXe link said:
Everyone know's you hate Blackhat, you're asking him questions that he 'probably' can't answer on purpose. I just helped him. He's making tutorials and you're like a little bug that is trying to get into his asscrack...

what asnwer he asked me ?
he just want to destroy , he doesn't care about anyone , i didn't say i'm pro , go check my main topic about these tutorials , i said i have average knowledge , and i'm gonig to learn you to get the same knowledge as me , so i didn't promise people to become like you [member=60]Opcode.eXe[/member]  , i didn't promise anyone to be that pro , i just want to make CLEO more easy to learn , that's it ,  no more no less
 

|]_ReT1neX_[|

Active member
Joined
Jul 28, 2014
Messages
132
Reaction score
0
Re: 12)GOSUB statement -TUT

Mr.Ze link said:
And also, Opcode, please, you went down so low that you are going to lie just so you can talk against me.

BlackHat showed no purpose to use gosub. After else_jump you could just put in the code, instead of putting gosub and making an entire new label. Saved text? Ha, nope. When you have then multiple nosubs, you're telling me it's easier than just looking at original label? Yeah, sure.

He hasn't explained half you did.


I still don't get it, WHY DO YOU CARE?  :motherofgod_

Y r'u hatin' so much?  :trollface:

Instead of HATING why don't you just create an other topic Better than this?  :trollface:

:watchout:
 

ThermaL

Expert
Joined
Oct 23, 2013
Messages
1,593
Reaction score
3
Re: 12)GOSUB statement -TUT

_ReT1neX_[| link=topic=9635.msg65460#msg65460 date=1417786847]

I still don't get it, WHY DO YOU CARE?  :motherofgod_

Y r'u hatin' so much?  :trollface:

Instead of HATING why don't you just create an other topic Better than this?  :trollface:

:watchout:
Why do you reply to a 5 months old post? :face_palm: Also, that user was banned long time ago, he won't see your reply.
 
Top