? How to run two loops at once? (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
This website has been moved, please see this post

How to run two loops at once?

  • #1 ✎ 1 Jbomb6 Since I'm not the best at programming I've been just making games that don't really have a premise. One of these games right now I just call space. In it your a little space man flying around and there is this black hole slowly getting bigger and bigger. Once you touch it you die, eventually I want to turn it into more but that's all I have made so far. But anyway so the guy will move I made a loop and so the black hole will get bigger I made another loop too. But the thing is I can't have those going at once without adding something extra, I don't know that that extra is. I tried combining the loops but that won't work so if someone could help me it would be much appreciated. Posted
  • #2 ✎ 1884 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself You'll have to put all the code into one loop Make sure you're using different variables for each section Posted
  • #3 ✎ 477 SquareFingers
    I tried combining the loops but that won't work
    You mean, you tried combining the loops but the way you tried didn't work. What did you do, that didn't work? In what way didn't it work?
    Posted
  • #4 ✎ 120 kitesinpowerlines Avatar Block I didn't change my avatar for 30 days. Website Avatar Embargo I didn't change my avatar for 90 days Website Avatar Taboo I didn't change my avatar for 180 days Website Late response but you could put the loops in DEFs and call them in a single loop. VAR S: VAR HIT: VAR B:VAR X=150:VAR Y=100 SPSET 0,'SpaceMan sprite SPSET 1,'Blackhole Sprite SPOFS 0,X,Y:SPOFS 1,150,0:SPCOL 0 WHILE 1 INC S,0.2 SpaceMan Blackhole IF HIT==TRUE THEN BREAK VSYNC WEND END DEF SpaceMan B=BUTTON() IF B AND #UP THEN DEC Y IF B AND #RIGHT THEN INC X IF B AND #DOWN THEN INC Y IF B AND #LEFT THEN DEC X SPOFS 0,X,Y END DEF Blackhole HIT=SPHITSP(1) SPCOL 1,TRUE: SPSCALE 1,S,S END Note: I didn't test this but it should be a simple way of achieving what you want. Posted Edited by kitesinpowerlines
  • #5 ✎ 202 JustGreat First Month Joined in the very first month of SmileBASIC Source Website Avatar Taboo I didn't change my avatar for 180 days Website Night Person I like the quiet night and sleep late. Express Yourself
    Late response but you could put the loops in DEFs and call them in a single loop.
    I second this. Especially if you're going to make the game bigger, you should make each function modular with DEF blocks.
    Posted
  • #6 ✎ 1884 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself
    Late response but you could put the loops in DEFs and call them in a single loop. ... Note: I didn't test this but it should be a simple way of achieving what you want.
    The SPCOL for the black hole needs to have scale adjustment enabled.
    Posted
  • #7 ✎ 202 JustGreat First Month Joined in the very first month of SmileBASIC Source Website Avatar Taboo I didn't change my avatar for 180 days Website Night Person I like the quiet night and sleep late. Express Yourself
    Late response but you could put the loops in DEFs and call them in a single loop. ... Note: I didn't test this but it should be a simple way of achieving what you want.
    The SPCOL for the black hole needs to have scale adjustment enabled.
    Honestly, for something that's always going to be a circle, wouldn't a simple radius check be more advised? Edit: Now that I think about it, wouldn't GCIRCLE be better than scaling a sprite?
    Posted Edited by JustGreat
  • #8 ✎ 120 kitesinpowerlines Avatar Block I didn't change my avatar for 30 days. Website Avatar Embargo I didn't change my avatar for 90 days Website Avatar Taboo I didn't change my avatar for 180 days Website
    Late response but you could put the loops in DEFs and call them in a single loop. ... Note: I didn't test this but it should be a simple way of achieving what you want.
    The SPCOL for the black hole needs to have scale adjustment enabled.
    Honestly, for something that's always going to be a circle, wouldn't a simple radius check be more advised? Edit: Now that I think about it, wouldn't GCIRCLE be better than scaling a sprite?
    Idk, I figured scaling a sprite is easy to comprehend so I went with that option. Also, not noted in the code but if going with the scaling sprite option, I would recommend using SPHOME to center the point of collision (or wherever it needs to be)
    Posted
  • #9 ✎ 1884 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself I think you only need to do the SPCOL 1,TRUE once, though I haven't really used SPCOL much so I'm not entirely certain. Posted
  • #10 ✎ 120 kitesinpowerlines Avatar Block I didn't change my avatar for 30 days. Website Avatar Embargo I didn't change my avatar for 90 days Website Avatar Taboo I didn't change my avatar for 180 days Website Ah, that would make sense, but I'm not entirely certain either. I'll test it out later. Posted
  • #11 ✎ 246 niconii Power User Video Games I like to play video games! Hobbies Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Drawing I like to draw! Hobbies I would use a radius distance check for collision rather than using the sprite, because otherwise that hitbox is gonna be a square, not a circle, and that'll get more and more noticeable as it grows. Posted