? CALL/CALLIDX/SPCOL? (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
Another contest? You asked for it!

CALL/CALLIDX/SPCOL?

  • #1 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies I’m making a game and on the touchscreen i have like 20 sprites that all need individual functionality so how would i do that using touch? Like if i tap one it will make it red and if i tap another one it’ll make it red and the previously tapped one white again. But on top of the color changing would be additional top screen stuff. what do i do? Examples? Posted
  • #2 ✎ 1305 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself You can use SPHITRC to check if any sprites are inside a rectangular area: sprite_id = SPHITRC( rectangle_x , rectangle_y , rectangle_width , rectangle_height ) So, if you're trying to see which sprite is being touched, just use the touch coordinates as the rectangle position. Posted
  • #3 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    You can use SPHITRC to check if any sprites are inside a rectangular area: sprite_id = SPHITRC( rectangle_x , rectangle_y , rectangle_width , rectangle_height ) So, if you're trying to see which sprite is being touched, just use the touch coordinates as the rectangle position.
    Yeah but i need to be able to move the sprites around. I was thinking more invisible sprite to visible sprite on the touchscreen collision. I was told that CALL and CALLIDX were crucial to doing what i need. How do those work?
    Posted
  • #4 ✎ 115 raimondz First Week Joined in the very first week of SmileBASIC Source Website Expert Programmer Programming no longer gives me any trouble. Come to me for help, if you like! Programming Strength Night Person I like the quiet night and sleep late. Express Yourself "CALL sprite" will call any label or function assigned to each sprite using SPFUNC. You should use it if you're not using any auxiliar variable(AKA metadata) to represent your sprite. Example: VAR SP1=SPSET(0) VAR SP2=SPSET(1) SPFUNC SP1,"A" SPFUNC SP2,"B" 'This sentence will call the functions associate with each sprite. CALL sprite DEF A ? CALLIDX END DEF B ? "SPRITE NUMBER = ";CALLIDX END By the way, I wouldn't use "CALL sprite" to do that. You can save the sprite obtained with sphitrc and move it with spofs if the touch time is greater than 1. If the touch time is one and the sprite's management number is different to the one stored, then you can change the color of the old one and store the new sprite's management number on that variable. Posted Edited by raimondz
  • #5 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    "CALL sprite" will call any label or function assigned to each sprite using SPFUNC. You should use it if you're not using any auxiliar variable(AKA metadata) to represent your sprite. Example: VAR SP1=SPSET(0) VAR SP2=SPSET(1) SPFUNC SP1,"A" SPFUNC SP2,"B" 'This sentence will call the functions associate with each sprite. CALL sprite DEF A ? CALLIDX END DEF B ? "SPRITE NUMBER = ";CALLIDX END By the way, I wouldn't use "CALL sprite" to do that. You can save the sprite obtained with sphitrc and move it with spofs if the touch time is greater than 1. If the touch time is one and the sprite's management number is different to the one stored, then you can change the color of the old one and store the new sprite's management number on that variable.
    Ah ok i think i understand. I’ll try that.
    Posted
  • #6 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    "CALL sprite" will call any label or function assigned to each sprite using SPFUNC. You should use it if you're not using any auxiliar variable(AKA metadata) to represent your sprite. Example: VAR SP1=SPSET(0) VAR SP2=SPSET(1) SPFUNC SP1,"A" SPFUNC SP2,"B" 'This sentence will call the functions associate with each sprite. CALL sprite DEF A ? CALLIDX END DEF B ? "SPRITE NUMBER = ";CALLIDX END By the way, I wouldn't use "CALL sprite" to do that. You can save the sprite obtained with sphitrc and move it with spofs if the touch time is greater than 1. If the touch time is one and the sprite's management number is different to the one stored, then you can change the color of the old one and store the new sprite's management number on that variable.
    So i used this code and using either CALL”A” or CALL”B” Always resulted the CALLIDX value in each function as 0. I was doing this as a test and i don’t know why that doesn’t work, CALL”A” should give me “0” andCALL”B”should give me “SPRITE NUMBER = 1” shouldn’t it?
    Posted
  • #7 ✎ 766 Lumage Head Admin CALL SPRITE evaluates each function attached to sprites with SPFUNC, updating CALLIDX. Ordinary call will not work. Posted
  • #8 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    CALL SPRITE evaluates each function attached to sprites with SPFUNC, updating CALLIDX. Ordinary call will not work.
    So what do i need to do then besides CALL?
    Posted
  • #9 ✎ 766 Lumage Head Admin Like others have said, you don't really need SPFUNC to do this: SPHIT* returns the collision ID. SPFUNC is useful when you want to automatically evaluate the state of all sprites, which you're not doing here. DEF MySpriteFunction ID SPCOLOR ID, #RED 'etc END WHILE 1 TOUCH OUT TTIME, TX, TY IF TTIME > 0 && SPHITRC(TX, TY, 1, 1) != -1 THEN MySpriteFunction SPHITRC(TX, TY, 1, 1) ENDIF WEND something like this probably works Posted Edited by Lumage
  • #10 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    RTFM DEF MySpriteFunction ID SPCOLOR ID, #RED 'etc END WHILE 1 TOUCH OUT TTIME, TX, TY IF TTIME > 0 && SPHITRC(TX, TY, 1, 1) != -1 THEN MySpriteFunction SPHITRC(TX, TY, 1, 1) ENDIF WEND something like this probably works
    This doesn’t work?? I’m trying to find out why, probably something i did
    Posted
  • #11 ✎ 766 Lumage Head Admin
    RTFM DEF MySpriteFunction ID SPCOLOR ID, #RED 'etc END WHILE 1 TOUCH OUT TTIME, TX, TY IF TTIME > 0 && SPHITRC(TX, TY, 1, 1) != -1 THEN MySpriteFunction SPHITRC(TX, TY, 1, 1) ENDIF WEND something like this probably works
    This doesn’t work?? I’m trying to find out why, probably something i did
    What's the error given?
    Posted
  • #12 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    RTFM DEF MySpriteFunction ID SPCOLOR ID, #RED 'etc END WHILE 1 TOUCH OUT TTIME, TX, TY IF TTIME > 0 && SPHITRC(TX, TY, 1, 1) != -1 THEN MySpriteFunction SPHITRC(TX, TY, 1, 1) ENDIF WEND something like this probably works
    This doesn’t work?? I’m trying to find out why, probably something i did
    What's the error given?
    There wasn’t any syntax errors, it just doesn’t work?? I’m making a test program right now to see if i did something wrong. I think i know what i did but let me check.
    Posted
  • #13 ✎ 766 Lumage Head Admin
    There wasn’t any syntax errors, it just doesn’t work?? I’m making a test program right now to see if i did something wrong. I think i know what i did but let me check.
    Check the specification for TOUCH and SPHITRC. I've never used them, so I can't be sure.
    Posted
  • #14 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    RTFM DEF MySpriteFunction ID SPCOLOR ID, #RED 'etc END WHILE 1 TOUCH OUT TTIME, TX, TY IF TTIME > 0 && SPHITRC(TX, TY, 1, 1) != -1 THEN MySpriteFunction SPHITRC(TX, TY, 1, 1) ENDIF WEND something like this probably works
    This doesn’t work?? I’m trying to find out why, probably something i did
    What's the error given?
    There wasn’t any syntax errors, it just doesn’t work?? I’m making a test program right now to see if i did something wrong. I think i know what i did but let me check.
    Ok so i created a new test file folder and started up a new program without anything in it and ran:ACLS XSCREEN 2 DEF SELECT ID SPCOLOR ID,#RED END DISPLAY 1 SPSET 1,1 SPOFS 1,150,100 WHILE 1 TOUCH OUT TTIME,TX,TY IF TTIME > 0 && SPHITRC(TX,TY,1,1) != -1 THEN SELECT SPHITRC(TX,TY,1,1) ENDIF WEND Nothing happens when i touch it.
    Posted
  • #15 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    There wasn’t any syntax errors, it just doesn’t work?? I’m making a test program right now to see if i did something wrong. I think i know what i did but let me check.
    Check the specification for TOUCH and SPHITRC. I've never used them, so I can't be sure.
    We are using correct syntax
    Posted
  • #16 ✎ 766 Lumage Head Admin oh um you're missing SPCOL, I think. Posted
  • #17 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies
    oh um you're missing SPCOL, I think.
    YES that was the problem dont embarrass me like that again lmao
    Posted
  • #18 ✎ 82 Warrior Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Drawing I like to draw! Hobbies So anyways now that is working i should probably put up a tutorial of some sort to not only remind me but tell other people how to do stuff like i am, where there’s a bunch of things on screen that all have individual assets. Posted