Quote: "It certainly could make management a bit easier if you do something like this "
Precisely, by using string parameters for such as sprite creation, you can have string templates for different things and combine them when passed to the function.
mySprite = MyCreateSprite( thisImage , frogSpriteTemplate$ + defaultColour$ + StartPosition$ )
Code management is also easier as the handling of each parameter is coded in a case section of a select structure, making adding parameters a matter of dropping another block in.
totalPairs = getStringTokens( StringParameter$ , "," )
for pair = 1 to totalPairs
pairData$ = getStringToken( StringParameter$ , "," , pair )
param$ = getStringToken( pairData$ , "=" , 1 )
value$ = getStringToken( pairData$ , "=" , 2 )
select param$
case "X"
spriteX = val( value$ )
endcase
case "Y"
spriteY = val( value$ )
endcase
...
endselect
next pair
You just have to get over any hangups about string manipulation
EDIT:
As a freebie for anyone needing an idea about data files and using stringtokens, here's a function from my current project
function Game_LoadUserData()
thisFile = Core_SafeOpenToRead( "userdata.dat" )
if thisFile > 0
thisLine$ = Core_SafeReadLine( thisFile )
thisVersion$ = getStringToken( thisLine$ , "," , 1 )
select thisVersion$
case default
// 1.0
if countstringTokens( thisLine$ , "," ) <> 5
Core_SetErrorState( "Invalid User File")
else
// Header
GamePlayer.dataVersion$ = thisVersion$
GamePlayer.userName$ = Core_LeftTrim( getStringToken( thisLine$ , "," , 2 ) )
GamePlayer.uniqueID$ = Core_LeftTrim( getStringToken( thisLine$ , "," , 3 ) )
GamePlayer.lastSaved = val( getStringToken( thisLine$ , "," , 4 ) )
GamePlayer.levelCleared = val( getStringToken( thisLine$ , "," , 5 ) )
// Read Levels
repeat
thisLine$ = Core_SafeReadLine( thisFile )
if countstringTokens( thisLine$ , ":" ) > 1
thisLevel = val( getstringToken( thisLine$ , ":" , 1 ) )
if thisLevel > 0 and thisLevel <= Game.levelMax
thisData$ = getstringToken( thisLine$ , ":" , 2 )
GameLevel[ thisLevel ].timesWon = val( getstringToken( thisData$ , ";" , 1 ) )
GameLevel[ thisLevel ].scoreTop = val( getstringToken( thisData$ , ";" , 2 ))
GameLevel[ thisLevel ].scoreTopMoves = val( getstringToken( thisData$ , ";" , 3 ) )
GameLevel[ thisLevel ].movesMin = val( getstringToken( thisData$ , ";" , 4 ) )
GameLevel[ thisLevel ].movesMinScore = val( getstringToken( thisData$ , ";" , 5 ) )
endif
endif
until fileeof( thisFile ) = 1
endif
endcase
endselect
closeFile( thisFile )
endif
GamePlayer.levelShowing = GamePlayer.levelCleared + 1
Game_CalcUserTotals()
endfunction
It uses some other functions and a lot of UDTs, but their purpose should be obvious from the names and their use should give some ideas.
Modularization Baby