Okay, as promised, I submitted to bug list with full project attached.
And I've attached the built version here.
The images were taken from the examples provided with AGK.
Here is the code (for easy reference):
rem
rem AGK Application
rem
remstart
Purpose:
This project is intended to illustrate a problem with
passing UDTs through multiple levels of function calls.
Author:
Cynthia R. Douglas (aka Ancient Lady), Triassic Associates, Inc.
remend
/////////////////////////////////////////
// TYPES ////////////////////////////////
/////////////////////////////////////////
//
// images
//
TYPE tImage
i_mid AS integer // id assigned to image when it is created
xoff AS float // percentage of sprite width to set x offset to
yoff AS float // percentage of sprite height to set y offset to
ENDTYPE
//
// basic information for a sprite
//
TYPE tSprite
i_sid AS integer // sprite number returned upon creation
i_ind AS integer // media image index to use for sprige
i_dep AS integer // depth to display sprite at
x# AS float // X position to display sprite at
y# AS float // Y position to display sprite at
scaleX# AS float // scale to apply in X direction
scaleY# AS float // scale to apply in Y direction
angle# AS float // angle to apply to sprite
ENDTYPE
//
// bridge point
//
TYPE tBridgePoint
i_sid AS integer // sprite number returned upon creation
i_did AS integer // sprite number for dummy sprite
ENDTYPE
/////////////////////////////////////////
// GLOBALS //////////////////////////////
/////////////////////////////////////////
global dim g_Images[100] AS tImage
global dim g_br_dmmy[3,2] AS float
global dim g_BRp[3,2] AS tBridgePoint
global g_br_cnt AS integer
global g_BRpt AS tBridgePoint
global g_spr1 AS tSprite
global g_spr2 AS tSprite
// this variable will let you test three things
// 0 = just put up sprites
// 1 = make bridge that works
// 2 = make bridge that fails
global g_tst AS integer
dim g_tst_msg[3,2] AS string
/////////////////////////////////////////
// INITIALIZATION ///////////////////////
/////////////////////////////////////////
loadImages()
loadGameInfo()
createLevel()
/////////////////////////////////////////
// MAIN LOOP ////////////////////////////
/////////////////////////////////////////
do
Print("All functions have a tSprite variable as"+chr(10)+"the only calling parameter")
Print("Function C (FC) - display main sprite")
Print("Function GG (FGG) - add 'bridge' to sprite")
Print("Function BG (FBG) - call FC with passed sprite"+chr(10)+" variable, then add 'bridge'")
Print("Test 1: FC only")
Print("Test 2: FC followed by FGG")
Print("Test 3: FBG only"+chr(10))
Print("Current Test: "+str(g_tst+1))
// we don't need to test for going past 3 because test 3 always fails
Print("Touch for Test: "+str(g_tst+2))
if GetPointerPressed() = 1
// bump the test level
g_tst = Mod((g_tst+1),3)
// display to show we got this far
Print(g_tst_msg[g_tst,0])
Sync()
// reload
createLevel()
endif
Sync()
loop
end
/////////////////////////////////////////
// FUNCTIONS ////////////////////////////
/////////////////////////////////////////
function loadImages()
// in the actual game, lines are read from a file
// that declare the index to use, the name of the
// image file and the offsets (as percentage) to use
// get first image
g_Images[10].i_mid = LoadImage("blue.png")
g_Images[10].xoff = 0.5
g_Images[10].yoff = 0.5
// get the second image
g_Images[20].i_mid = LoadImage("silver.png")
g_Images[20].xoff = 0.5
g_Images[20].yoff = 0.5
endfunction
function loadGameInfo()
// in the actual game, lines are read from a file
// that define lots of things for main game setup/play
// set up the dummy size
g_br_dmmy[0,0] = 64.0 // width
g_br_dmmy[0,1] = 32.0 // height
// these x,y pairs define offset from the center of main sprite
// set up for angle=0
g_br_dmmy[1,0] = 0.0
g_br_dmmy[1,1] = -20.0
// set up for angle=90
g_br_dmmy[2,0] = 20.0
g_br_dmmy[2,1] = 0.0
// turn gravity off
SetPhysicsGravity(0.0,0.0)
// set to base
SetViewOffset(0.0,0.0)
// set a virtual resolution of
SetVirtualResolution(480, 480)
// we want to see dummy things
SetPhysicsDebugOn()
// initialise counts/flags
g_tst = 0
g_br_cnt = 0
endfunction
function processTheSprite(in_spr AS tSprite)
// set the indicated depth
SetSpriteDepth(in_spr.i_sid, in_spr.i_dep)
// apply scale
SetSpriteScale(in_spr.i_sid, in_spr.scaleX#, in_spr.scaleY#)
// calculate and set the offset
xoff# = GetSpriteWidth(in_spr.i_sid) * g_Images[in_spr.i_ind].xoff
yoff# = GetSpriteHeight(in_spr.i_sid) * g_Images[in_spr.i_ind].yoff
SetSpriteOffset(in_spr.i_sid, xoff#, yoff#)
// set it in the right place
SetSpritePositionByOffset(in_spr.i_sid, in_spr.x#, in_spr.y#)
// now apply the angle
SetSpriteAngle(in_spr.i_sid, in_spr.angle#)
// make sure it is visible
SetSpriteVisible(in_spr.i_sid, 1)
endfunction
function makeABridgeGOOD(b_spr AS tSprite)
// in the actual game, a bunch of other stuff is done here as well
// create the dummy sprite
i_did = CreateDummySprite()
// the next depends on the orientation of the main sprite
if b_spr.angle# < 90.0
// set height and width
wid# = g_br_dmmy[0,0]
hih# = g_br_dmmy[0,1]
// pick dummy offset pair
od = 1
else
// set height and width
wid# = g_br_dmmy[0,1]
hih# = g_br_dmmy[0,0]
// pick dummy offset pair
od = 2
endif
// adjust for parent size
wid# = wid# * b_spr.scaleX#
hih# = hih# * b_spr.scaleY#
// create the size
SetSpriteSize(i_did,wid#,hih#)
// calculate and set the offset
xoff# = wid# * g_Images[b_spr.i_ind].xoff
yoff# = hih# * g_Images[b_spr.i_ind].yoff
SetSpriteOffset(i_did, xoff#, yoff#)
// figure out the position for dummy sprite
x1# = b_spr.x# + g_br_dmmy[od,0]
y1# = b_spr.y# + g_br_dmmy[od,1]
// set the dummy sprite location to be
// position based on center of main sprite
SetSpritePositionByOffset(i_did,x1#,y1#)
// add physics to them (to make it visible for this demo)
SetSpritePhysicsOn(i_did,1)
// store the data
g_BRpt.i_sid = b_spr.i_sid
g_BRpt.i_did = i_did
endfunction
function makeABridgeBAD(b_spr AS tSprite)
// in the actual game, a bunch of other stuff is done here as well
// process the parent sprite
// ****** THIS IS THE PLACE WHERE IT GOES BAD *****
// ****** the error message will show a randomish sprite number at line 168
processTheSprite(b_spr)
// create the dummy sprite
i_did = CreateDummySprite()
// the next depends on the orientation of the main sprite
if b_spr.angle# < 90.0
// set height and width
wid# = g_br_dmmy[0,0]
hih# = g_br_dmmy[0,1]
// pick dummy offset pair
od = 1
else
// set height and width
wid# = g_br_dmmy[0,1]
hih# = g_br_dmmy[0,0]
// pick dummy offset pair
od = 2
endif
// adjust for parent size
wid# = wid# * b_spr.scaleX#
hih# = hih# * b_spr.scaleY#
// create the size
SetSpriteSize(i_did,wid#,hih#)
// calculate and set the offset
xoff# = wid# * g_Images[b_spr.i_ind].xoff
yoff# = hih# * g_Images[b_spr.i_ind].yoff
SetSpriteOffset(i_did, xoff#, yoff#)
// figure out the position for dummy sprite
x1# = b_spr.x# + g_br_dmmy[od,0]
y1# = b_spr.y# + g_br_dmmy[od,1]
// set the dummy sprite location to be
// position based on center of main sprite
SetSpritePositionByOffset(i_did,x1#,y1#)
// add physics to them (to make it visible for this demo)
SetSpritePhysicsOn(i_did,1)
// store the data
g_BRpt.i_sid = b_spr.i_sid
g_BRpt.i_did = i_did
endfunction
function createLevel()
// in the actual game, lines are read from a file
// that define lots of bits to create and display
// make sure old sprites gone
clearLevel()
// clear count
g_br_cnt = 0
// create new level data
// get the sprite data
g_spr1.i_ind = 10
g_spr1.i_dep = 10
g_spr1.x# = 250.0
g_spr1.y# = 250.0
g_spr1.scaleX# = 1.0
g_spr1.scaleY# = 1.0
g_spr1.angle# = 0.0
g_spr2.i_ind = 20
g_spr2.i_dep = 10
g_spr2.x# = 350.0
g_spr2.y# = 350.0
g_spr2.scaleX# = 1.0
g_spr2.scaleY# = 1.0
g_spr2.angle# = 90.0
// create the main sprites
// this is done here because in the real program there are
// several different ways the parent sprite is created,
// some of which use a defined id instead of the autogenned one
g_spr1.i_sid = CreateSprite(g_Images[g_spr1.i_ind].i_mid)
g_spr2.i_sid = CreateSprite(g_Images[g_spr2.i_ind].i_mid)
// get index for briges
br_ind = g_br_cnt
// increment count of bridges
INC g_br_cnt
// do the tests
select g_tst
case 0:
processTheSprite(g_spr1)
processTheSprite(g_spr2)
endcase
case 1:
// make first half of bridge
processTheSprite(g_spr1)
makeABridgeGOOD(g_spr1)
g_BRp[br_ind,0] = g_BRpt
// make second half of bridge
processTheSprite(g_spr2)
makeABridgeGOOD(g_spr2)
g_BRp[br_ind,1] = g_BRpt
endcase
case 2:
// make first half of bridge
makeABridgeBAD(g_spr1)
g_BRp[br_ind,0] = g_BRpt
// make second half of bridge
makeABridgeBAD(g_spr2)
g_BRp[br_ind,1] = g_BRpt
endcase
endselect
endfunction
function clearLevel()
if g_br_cnt > 0
for i=0 to g_br_cnt-1
for j=0 to 1
g_BRpt = g_BRp[j,i]
DeleteSprite(g_BRpt.i_sid)
DeleteSprite(g_BRpt.i_did)
next i
next i
endif
endfunction
The attached file has a type defined that I ended up not using. And the comment listing the error line is not correct. Sorry about that.
Cheers,
Ancient Lady