
-----------------------------------
goober999
Tue Jan 16, 2007 5:48 pm

Problem With Pic.Draw
-----------------------------------
Just Working on my grade 10 summative mario game, I am getting a "Variable has no Value" error message. I realize its probably sumthing stupid I have overlooked but its driving me nuts. Any help would be greatly appreciated.


%%Tiling Engine For Mario v1.0
setscreen ("graphics:640;640")
setscreen ("offscreenonly")

%%Declare Variables
const td : int := 20    %%TILES DOWN ***
const ta : int := 72    %%TILES ACROSS (THE LENGTH OF THE LEVEL)
const TileWidth : int := 32 %%TILE WIDTH ***
const nt : int := 5     %%NUMBER OF TILES BEING USED
const background : int := Pic.FileNew ("tiles/Back2.bmp")
var loader : array 1 .. 400 of int
var level1 : array 0 .. 5 of int
var Across : array 1 .. ta of string
var rander, tiles, tnum, StartPosition, lchng : int
var Locations : array 1 .. (ta * td) of string
var TileImages : array 1 .. (ta * td) of int
var chars : array char of boolean
var lend : int := (TileWidth * ta - 640) * -1
var jc : int := 14
var mem2, do : int := 1
var cntr : int := 0
var enemy2 : int
open : tiles, "tiles.txt", get
open : enemy2, "enemy.txt", get
var achng : int := 1
var LVS : int := 3
var SCORE : int := 000
var ex, ey, ed : flexible array 1 .. 0 of int
var enemy : flexible array 1 .. 0, 1 .. 0 of int
var echng, echng2 : flexible array 1 .. 0 of int
var ecnt : int := 1
var deaths : flexible array 1 .. 0 of string
var test : string := "f"

%%Mario Parameters
var mx, my, mcount, chng, vchng, mbase : int
var chars1 : array char of boolean
var jumpf : int := 1
var dir : string
mbase := 32
dir := "right"
mx := 1
my := mbase
chng := 8
mcount := 1
var mario : array 1 .. 8 of int
var jumping, jumping2 : string := "false"
var shroom : int
shroom := Pic.FileNew ("Question Block/1up.bmp")
Pic.SetTransparentColor (shroom, white)
var shroomer : string := "f"
var schng : int := 5


%%Loads Mario
for i : 1 .. 8
    mario (i) := Pic.FileNew ("mario" + intstr (i) + ".BMP")
end for
Pic.Draw (mario (1), mx, my, picMerge)


%%Load The Background
Pic.Draw (background, 1, 1, picCopy)
%%Load the map into an array
StartPosition := 0
for i : 1 .. td
    for ii : 1 .. ta
        exit when eof (tiles)
        get : tiles, Across (ii)
    end for
    for ii : 1 .. ta
        Locations (ii + StartPosition) := Across (ii)
        if strint (Locations (ii + StartPosition)) not= 2 then
            cntr := cntr + 1
        end if
    end for
    StartPosition += ta
end for
close : tiles

%%Load up the tiles
for i : 1 .. 8
    TileImages (i) := Pic.FileNew ("tiles/" + intstr (i) + ".bmp")   %Load every image, in order, from the file folder that holds the tiles.
end for

%%Make White Tiles Transparent
for i : 1 .. (ta * td)
    Pic.SetTransparentColor (TileImages (strint (Locations (i))), white)
end for

lchng := 0
var cx, cy, cd : array 1 .. cntr of int
var sx, sy, plh : int := 0
var sx2, sy2 : int := 0

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%COLLISION DETECTION VERTICLE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function detect (n : string, x : int, y : int) : string
    for i : 1 .. cntr
        if (x + 32) >= cx (i) and x = cy (i) and y  cx (i) and n = "u" then
                result "u"
            elsif y + 56 >= cy (i) and x < cx (i) + 6 and x + 56 > cx (i) + 26 and n = "d" then
                if cd (i) = 4 then
                    shroomer := "t"
                    plh := i
                    sx2 := cx (i)
                    sy2 := cy (i)
                end if
                result "d"
            end if
        end if
    end for
    result "f"
end detect
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%COLLISION DETECTION HORIZONTAL%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function detect2 (n : string, x : int, y : int) : string
    for i : 1 .. cntr
        if (x + 32) >= cx (i) and x = cy (i) and y = cx (i) + 25 and y + 1 < cy (i) + 32 and n = "l" then
                result "l"
            end if
        end if
    end for
    result "f"
end detect2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% process music
%     Music.PlayFile ("music.MID")
% end music
% fork music
    
%%The Tile Mapper
loop
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        if mx >= 320 and lchng >= lend and detect2 ("r", mx, my) not= "r" then
            lchng := lchng - 5
        end if
    end if
    if chars (KEY_LEFT_ARROW) then
        if lchng < 0 and mx  cntr then
                mem2 := 1
            end if
            cx (mem2) := TileWidth * XPositionCounter + lchng
            cy (mem2) := TileWidth * YPositionCounter - TileWidth
            cd (mem2) := strint (Locations (i))
            mem2 := mem2 + 1
        end if
        XPositionCounter += 1
    end for
        
        loop
            new ex , achng
            new ey , achng
            new ed , achng
            new enemy, achng, 2
            new deaths , achng
            new echng , achng
            new echng2, achng 
            get : enemy2, ed (achng)
            put ed (achng)
            exit when eof (enemy2)
            achng := achng + 1
        end loop
            
        for i : 1 .. achng
            for j : 1 .. 2
                enemy (i, j) := Pic.FileNew ("tiles/4" + intstr (j) + ".bmp")
            end for
        end for
        
        for i : 1 .. achng
            echng (i) := 4
            echng2 (i) := 7
            deaths (i) := "f"
        end for
        put achng
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%One Up Shroom%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if shroomer = "t" then
        Pic.Draw (shroom, cx (plh) + sx, cy (plh) + sy, picMerge)
        if sy + cy (plh) < sy2 + 32 then
            sy := sy + 1
        end if
        if sy + cy (plh) > sy2 + 31 then
            sx := sx + schng
        end if
        if detect2 ("r", sx + cx (plh), sy + cy (plh)) = "r" then
            schng := schng * -1
        end if
        if detect2 ("l", sx + cx (plh), sy + cy (plh)) = "l" then
            schng := schng * -1
        end if
        if mx + 56 > sx + cx (plh) and mx < sx + 32 + cx (plh) and my < sy + 32 + cy (plh) and my + 56 > sy + cy (plh) then
            shroomer := "f"
            LVS := LVS + 1
            SCORE := SCORE + 100
        end if
    end if

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ENEMY CONTROL%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    for i : 1 .. achng
        if deaths (i) = "f" then
            Pic.Draw (enemy (i, ecnt), cx (ed (i)) + ex (i), cy (ed (i)) + 32, picMerge)
            ex (i) := ex (i) + echng (i)
            if detect2 ("l", ex (i) + cx (ed (i)), ey (i)) = "l" then
                echng (i) := echng (i) * -1
            end if
            if detect2 ("r", ex (i) + cx (ed (i)), ey (i)) = "r" then
                echng (i) := echng (i) * -1
            end if
            if detect ("u", ex (i) + cx (ed (i)), ey (i)) not= "u" then
                ey (i) := ey (i) - 7
            end if
            if mx + 32 > ex (i) + cx (ed (i)) and mx < ex (i) + cx (ed (i)) + 32 and my < ey (i) + 32 and my + 56 > ey (i) then
                test := "t"
                if my > ey (i) + 24 and jumping2 = "true" then
                    Pic.Free (enemy (i, ecnt))
                    deaths (i) := "t"
                    jumping := "true"
                    SCORE := SCORE + 200
                end if
            else
                test := "f"
            end if
        end if
    end for
    if ecnt < 2 then
        ecnt := 2
    else
        ecnt := 1
    end if

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%MARIO%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %Walking Right Sequence
    Input.KeyDown (chars1)
    if chars1 (KEY_RIGHT_ARROW) and jumping = "false" and jumping2 = "false" then %Code for walking right
        dir := "right"
        if mcount = 2 or mcount > 2 then
            mcount := 1
        elsif mcount < 2 then
            mcount := mcount + 1
        end if
        if mx < 320 and detect2 ("r", mx, my) not= "r" then
            for i : 1 .. chng
                mx := mx + 1

                exit when detect ("r", mx, my) = "r"
            end for
        end if
        if lchng 