rustler Posted January 6, 2011 Share Posted January 6, 2011 Hi all, I please need some help with gosub & jumps I'm spawning a heli with a magnet and a euros. Marker on the heli, when I enter the heli marker is then disabled and new marker created on euros. When I exit the heli, marker is disabled on euros and re-created on heli. Here is part of the code :AKT02wait 0 msif 00DB: actor $PLAYER_ACTOR in_car $car_numjf @AKT020186: $62 = create_marker_above_car $eurosmarker.Disable($61):AKT02_3wait 0 msif044B: actor $PLAYER_ACTOR on_foot jf @AKT02_30186: $61 = create_marker_above_car $car_nummarker.Disable($62)jump @AKT02 As you can see it is looping - this is to keep it going as explained above. Now my problem is - however that part is working, I'm unable to continue with the rest of the mission. How can I get out of that loop without breaking it? Link to comment https://gtaforums.com/topic/466915-gosub-jumps/ Share on other sites More sharing options...
TheSiggi Posted January 6, 2011 Share Posted January 6, 2011 I'm not completely sure what you mean but :AKT02wait 0 msif 00DB: actor $PLAYER_ACTOR in_car $car_numjf @AKT020186: $62 = create_marker_above_car $euros:AKT02_3wait 0 msif044B: actor $PLAYER_ACTOR on_footjf @AKT02_3marker.Disable($62)jump @AKT02 makes more sense: As long as the player is in the car the marker will be there and it will disappear after the player left the car. This is not realy connected to gosubs at all but anyway: A gosub is used like this: gosub @Label_sub...:Label_sub[ code ]return So the engine reads through your script and as soon as it reaches the line including the gosub it will sort of keep that line in mind and will access the label you are 'going sub to' and runs through the code under your gosub label (in our example :Label_sub) and also labels after this one until it reches a return which makes the engine going back to the point were it left the main thread (the line below the gosub @). Link to comment https://gtaforums.com/topic/466915-gosub-jumps/#findComment-1060283211 Share on other sites More sharing options...
Dutchy3010 Posted January 6, 2011 Share Posted January 6, 2011 The_Siggi, if that's what he wants, then that's what he can make. It does make sense, and it does work how he did it. What you have to do further depends on whatever you want. Do you want the player to be near somewhere else? Then you have to check the place of the actor. If you don't want it to be wrecked, you have to make that check inside the loop too. You have to give us more information before we can help what you have to do next. Link to comment https://gtaforums.com/topic/466915-gosub-jumps/#findComment-1060283229 Share on other sites More sharing options...
rustler Posted January 7, 2011 Author Share Posted January 7, 2011 Morning and thanks for the replies. I thought of jumping into the deep end and get familiar with most of the coding, etc. But as you can see threads, jumps and gosubs are confusing the hell out of me. Basically I'm doing a shorter version of up up and away. I'm using Dutchy3010's R* mission template (from the tutorial). I run into the sphere, heli with magnet spawns with marker on it. When I climb into the heli that marker is disabled, a new car (euros) gets spawned with a marker on it. I fly to the euros, pick it up with magnet. When euros is wrecked mission fails or when I drop euros into sphere mission passed. That is working perfectly. Then I decided to improve on it a bit. So that's when I added that snipped of code to check - when in heli, disable heli's marker, create new marker on euro's. This should happen in a loop so that when I stop and get out of heli, marker should be on the heli again and disabled on euros. Then when I get back into heli it should be other way around again. Currently as is - the marker is working fine, but now when I pick up the euros and either wreck it or drop it into sphere I don't get mission fail or mission pass as the marker(s) check is looping and is not going anywhere. The rest of the code that checks if euros is wrecked and succesfully dropped is below this snipped. So it doesn't get executed. Link to comment https://gtaforums.com/topic/466915-gosub-jumps/#findComment-1060283620 Share on other sites More sharing options...
toonskull Posted January 7, 2011 Share Posted January 7, 2011 The big difference between jump and gosub is; gosub saves the return point and jump does not. gosub is best used when you have something you want done again and again in different parts of the program. For example, my brother used gosub for a talk routine. This is NOT CLEO but part of his MAIN.SCM he wrote: //Play Audio Progressive Mode:MISSN_07_PLAYif 99@ == 0then 03CF: load_wav 45238 as 1 99@ += 198@ = 0 //Audio is not playing00BC: show_text_highpriority GXT 'DB01' time 3000 flag 1 endif 99@ == 2then 03CF: load_wav 45237 as 1 99@ += 198@ = 0 //Audio is not playing00BC: show_text_highpriority GXT 'DB02' time 9000 flag 1 endif 99@ == 4then 03CF: load_wav 45239 as 1 99@ += 198@ = 0 //Audio is not playing00BC: show_text_highpriority GXT 'DB03' time 10000 flag 1 endif 99@ == 6then 03CF: load_wav 45240 as 1 99@ += 198@ = 0 //Audio is not playing00BC: show_text_highpriority GXT 'DB04' time 3000 flag 1 endif 03D0: wav 1 loaded jf @MISSN_07_RETif98@ == 0 then03D1: play_wav 198@ = 1 endif 03D2: wav 1 ended jf @MISSN_07_RET040D: unload_wav 199@ += 1:MISSN_07_RETreturn//End of Audio So by calling this subroutine with gosub, and passing it the value of 99@ the characters say different phrases as the scene progresses. I never use jump tables myself because they confuse the hell out of me, but I do understand the concept. Jumping to the label means no going back, while gosub allows you the return point. Link to comment https://gtaforums.com/topic/466915-gosub-jumps/#findComment-1060283633 Share on other sites More sharing options...
Deji Posted January 7, 2011 Share Posted January 7, 2011 I think the origin of the question is based on adding numerous code loops. Instead of having code in different loops (also, remove the excessive use of wait's! only 1 is needed per loop), you want it to go all in one big loop: :AKT_MainLoopwhile true wait 0 ms 0256: player 0 defined // the player is not wasted or busted? jf break // if he was wasted or busted, break the looop (goto "return") if 00DB: actor $PLAYER_ACTOR in_car $car_num // if the player is in the heli then 0006: 40@ = 1 // we can check this to see if he's in the heli later... 0186: $62 = create_marker_above_car $euros // create marker above the euros marker.Disable($61) else 0006: 40@ = 0 0186: $61 = create_marker_above_car $car_num // else, create marker above the heli marker.Disable($62) end if 0039: 40@ == 1 then // mission code to do whilst in the heli else // mission code to do whilst not in the heli endendreturn // return and do mission cleanup It's in high construct, which is easier to apprehend. Compile and decompile it to get it in low form. I recommend naming your threads appropriately. It can be a big help when you move onto bigger things (I'm currently creating a submission similar to the taxi missions, but more complex - keeping the complexity of original Rockstar submissions) and helps you organise your code, especially when working with gosub's. This is the some code of my Chauffeur submission script source so far: 054C: use_GXT_table 'CHAUFF'gosub @CHAUF_SetupAndLoad // load models/anims and setup initial stuff:CHAUF_MainLoopwhile true 003D: gosub @CHAUF_Debug gosub @CHAUF_Process //gosub @CHAUF_MissionChecks might go next...end:CHAUF_SetupAndLoadgosub @CHAUF_LoadAnimsgosub @CHAUF_LoadModelsif $CHAUF_Help1Shown == 0then $CHAUF_Help1Shown = 1 03E5: show_text_box 'CHF_H1'endgosub @CHAUF_AttachDoorBoxes03C4: set_status_text $CHAUF_LevelCounter type 0 GXT 'CHLEVEL'gosub @CHAUF_NextStage // missions usually use a var (34@ in this case) to keep track of which part of the mission is active - this sub increases that var and resets timersreturn As you can see, there are a lot of subroutines named nicely so that I know whenever I need to do something, I can gosub to a particular thread, etc. Even if I only use the subroutine once, it still simply helps to keep the mission neat and understandable. Link to comment https://gtaforums.com/topic/466915-gosub-jumps/#findComment-1060283924 Share on other sites More sharing options...
rustler Posted January 7, 2011 Author Share Posted January 7, 2011 (edited) Hi Deji I have tried your code, but for some reason I just couldn't get it to work with my existing script. Then I took a clean stripped SCM file and just added the minimum coding and it's still not working. Your format is good, easy to read and understand - unlike R*s where the whole SCM file is full with green text from top to bottom (labels, gosubs & jumps) {use macro (Ctrl+J) "headsa"to insert a file header}{$VERSION 3.0.0000}thread 'MAIN'var$PLAYER_CHAR: Playerend // var01F0: set_max_wanted_level_to 6set_wb_check_to 000C0: set_current_time 8 004E4: unknown_refresh_game_renderer_at 2488.5601 -1666.84Camera.SetAtPos(2488.5601, -1666.84, 13.38)$PLAYER_CHAR = Player.Create(#NULL, 2488.5601, -1666.84, 13.38)$PLAYER_ACTOR = Actor.EmulateFromPlayer($PLAYER_CHAR)07AF: $PLAYER_GROUP = player $PLAYER_CHAR groupCamera.SetBehindPlayerset_weather 0wait 0 ms$PLAYER_CHAR.SetClothes("PLAYER_FACE", "HEAD", Head)$PLAYER_CHAR.SetClothes("JEANSDENIM", "JEANS", Legs)$PLAYER_CHAR.SetClothes("SNEAKERBINCBLK", "SNEAKER", Shoes)$PLAYER_CHAR.SetClothes("VEST", "VEST", Torso)$PLAYER_CHAR.Build$PLAYER_CHAR.CanMove = Truefade 1 (out) 0 msselect_interior 00629: change_stat 181 (islands unlocked) to 4016C: restart_if_wasted at 2027.77 -1420.52 15.99 angle 137.0 for_town_number 0016D: restart_if_busted at 1550.68 -1675.49 14.51 angle 90.0 for_town_number 00180: set_on_mission_flag_to $ONMISSION // Note: your missions have to use the variable defined here ($ONMISSION)03E6: remove_text_boxcreate_thread @MODEL// IDLE LOOP:leegwait 500jump @leegend_thread:MODELthread 'MODEL'//Load models0247: load_model #GREENWOO0247: load_model #EUROS038B: load_requested_models :MODEL_LOAD00D6: if or 8248: not model #GREENWOO available8248: not model #EUROS available004D: jump_if_false @MODEL_SPAWN 0001: wait 0 ms 0002: jump @MODEL_LOAD:MODEL_SPAWN0674: set_car_model #GREENWOO numberplate "ABCDEFG" 00A5: $greenwood = create_car #GREENWOO at 2458.2483 -1659.0264 13.3047 0186: $61 = create_marker_above_car $greenwood0674: set_car_model #EUROS numberplate "123456" 00A5: $euros = create_car #EUROS at 2480.5 -1659.0264 13.3047 :AKT_MainLoopwhile true wait 0 ms 0256: player 0 defined // the player is not wasted or busted? jf break // if he was wasted or busted, break the looop (goto "return") if 00DB: actor $PLAYER_ACTOR in_car $greenwood // if the player is in the heli then 0006: 4@ = 1 // we can check this to see if he's in the heli later... 0186: $62 = create_marker_above_car $euros // create marker above the euros marker.Disable($61) else 0006: 4@ = 0 0186: $61 = create_marker_above_car $greenwood // else, create marker above the heli marker.Disable($62) end if 0039: 4@ == 1 then // mission code to do whilst in the heli else // mission code to do whilst not in the heli endendreturn // return and do mission cleanup0249: release_model #GREENWOO0249: release_model #EUROSend_thread I know this is not PHP, but this SCM coding is way way out of my league. Not even close to PHP. Thanks guys Edited January 7, 2011 by rustler Link to comment https://gtaforums.com/topic/466915-gosub-jumps/#findComment-1060284371 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now