LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

CALL/CALLIDX/SPCOL?

Root / FAQs / [.]

MochaProbablyCreated:
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?

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.

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?

"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.

"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.

"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” and
CALL”B”
should give me “SPRITE NUMBER = 1” shouldn’t it?

CALL SPRITE evaluates each function attached to sprites with SPFUNC, updating CALLIDX. Ordinary call will not work.

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?

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

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

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?

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.

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.

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.

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

oh um you're missing SPCOL, I think.

oh um you're missing SPCOL, I think.
YES that was the problem dont embarrass me like that again lmao

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.