Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 manipulating the variable
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Boarder16




PostPosted: Sat Jan 03, 2004 11:44 pm   Post subject: manipulating the variable

hey this is for my game aswell...here the questions. In one process i am giving a variable a value then right after that i call another process, now this process is listed above the first one. The second(just called) process uses teh same variable and its value for some thing.(to move the bullet shoot, but thats different)... now the variable does not have a value the computer says as might be expected becasuei have run into it before...usually i just cut and paste the moving bullet into the first process..elimianting teh second all together, but i can't this time because it is a movement process....so how can i make it so the variable has the same value just given to it in the first process, in the second... teh variabel IS declared at the top of teh whole program so it should be global...any suggestions??
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Sun Jan 04, 2004 12:44 am   Post subject: (No subject)

if you posted some of the code it whould be alot easer to help you with your problem.

ushely if it is a goblae var it should be acsesable in all parts of the progame. you could be ruing in to porblems if you are forking somting with is reading or wiriting to a var at the same time as another part of your code alougth i think that is very unlikey. you could try making anothr var and just seting that equale to the one you are trying to acses.

i whould realy need to see your code.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Tony




PostPosted: Sun Jan 04, 2004 1:09 am   Post subject: (No subject)

you should just initialize a variable to have ANY value just to bypass turing's "possibiliy of fault" security Rolling Eyes
code:

var number:int := 0


you know that you will give that variable a value before it is accessed, but compiler thinks that you might want to try to access it before, so it bitches. This way you just fill it with a garbage value that is to be replaced.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Boarder16




PostPosted: Sun Jan 04, 2004 8:23 am   Post subject: (No subject)

no i know that part..its fine...i dunno if i explained it aswell as icoudl have...here i'll try and place some code shortly to better show u..
Boarder16




PostPosted: Sun Jan 04, 2004 8:33 am   Post subject: (No subject)

oh wait i figured out sumthing that might work...becasue its the bullet movin.. and they r both in processes they can't have the sam variable for the character movement and te bullet movement..cause they want to move differently...so it dosen't matter. i'll still post the final code so u can see
Boarder16




PostPosted: Sun Jan 04, 2004 8:53 am   Post subject: (No subject)

hey...now i have a different problem lol i think it has umthing to do with the variables changing in the first process..look
code:
%52,42 is starting locations
%Adding 40 as upward movement - 442 is over
%Adding 40 as rightward movement - 652 is over
%Character Last Move Notes         -Number-            -Dir. Facing-
%                                     1                     Up
%                                     2                    Down
%                                     3                    Left
%                                     4                    Right
process bullet_shoot_up
    loop
        by_loc := by_loc + 40
        Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy) %Load Background
        Pic.Draw (pic_b_u, bx_loc, by_loc, picMerge)
        exit when by_loc = 362
        delay (100)
    end loop
    Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)
end bullet_shoot_up

process bullet_shoot_down
    loop
        by_loc := by_loc - 40
        Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy) %Load Background
        Pic.Draw (pic_b_d, bx_loc, by_loc, picMerge)
        exit when by_loc = 82
        delay (100)
    end loop
    Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)
end bullet_shoot_down

process bullet_shoot_left
    loop
        bx_loc := bx_loc - 40
        Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy) %Load Background
        Pic.Draw (pic_b_l, bx_loc, by_loc, picMerge)
        exit when by_loc = 92
        delay (100)
    end loop
    Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)
end bullet_shoot_left

process bullet_shoot_right
    loop
        bx_loc := bx_loc + 40
        Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy) %Load Background
        Pic.Draw (pic_b_r, bx_loc, by_loc, picMerge)
        exit when by_loc = 572
        delay (100)
    end loop
    Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)
end bullet_shoot_right

process char_movement
    x_loc := 52
    y_loc := 42
    loop
        getch (char_move)
        if char_move = "w" then %-------------------------------Move Up-----------------------------------------------------
            if y_loc = 402 then      %Stops character from moving off the screen on the top
                %                     Checks to see if new coordinates are 'landmarks' and cannot be moved on
            elsif y_loc = 82 and x_loc = 92 then
            elsif y_loc = 82 and x_loc = 132 then
            elsif y_loc = 202 and x_loc = 252 then
            elsif y_loc = 202 and x_loc = 292 then
            elsif y_loc = 202 and x_loc = 332 then
            elsif y_loc = 202 and x_loc = 372 then
            elsif y_loc = 202 and x_loc = 412 then
            elsif y_loc = 202 and x_loc = 452 then
            elsif y_loc = 322 and x_loc = 52 then
            elsif y_loc = 362 and x_loc = 92 then
            elsif y_loc = 362 and x_loc = 532 then
            elsif y_loc = 362 and x_loc = 572 then
            elsif y_loc = 362 and x_loc = 612 then
            elsif y_loc = 42 and x_loc = 532 then
            elsif y_loc = 82 and x_loc = 572 then
            elsif y_loc = 122 and x_loc = 612 then
            else
                y_loc := y_loc + 40  %Allows the character to move
            end if
            Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)         %Load Background
            Pic.Draw (pic_u, x_loc, y_loc, picMerge)
            char_last_move := 1
        elsif char_move = "s" then     %----------------------------Move Down--------------------------------------------------
            if y_loc = 42 then       %Stops character from moving off the screen on the bottom
                %                     Checks to see if new coordinates are 'landmarks' and cannot be moved on
            elsif y_loc = 82 and x_loc = 92 then
            elsif y_loc = 82 and x_loc = 132 then
            elsif y_loc = 282 and x_loc = 252 then
            elsif y_loc = 282 and x_loc = 292 then
            elsif y_loc = 282 and x_loc = 332 then
            elsif y_loc = 282 and x_loc = 372 then
            elsif y_loc = 282 and x_loc = 412 then
            elsif y_loc = 282 and x_loc = 452 then
            elsif y_loc = 322 and x_loc = 572 then
            elsif y_loc = 242 and x_loc = 612 then
            elsif y_loc = 162 and x_loc = 532 then
            elsif y_loc = 122 and x_loc = 492 then
            elsif y_loc = 82 and x_loc = 452 then
            elsif y_loc = 282 and x_loc = 92 then
            elsif y_loc = 282 and x_loc = 132 then
            else
                y_loc := y_loc - 40  %Allows the character to move
            end if
            Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)         %Load Background
            Pic.Draw (pic_d, x_loc, y_loc, picMerge)
            char_last_move := 2
        elsif char_move = "a" then     %-----------------------------Move Left---------------------------------------------------
            if x_loc = 52 then       %Stops character from moving off the screen on the left
                %                     Checks to see if new coordinates are 'landmarks' and cannot be moved on
            elsif x_loc = 172 and y_loc = 42 then
            elsif x_loc = 172 and y_loc = 122 then
            elsif x_loc = 172 and y_loc = 162 then
            elsif x_loc = 172 and y_loc = 202 then
            elsif x_loc = 172 and y_loc = 242 then
            elsif x_loc = 492 and y_loc = 242 then
            elsif x_loc = 92 and y_loc = 362 then
            elsif x_loc = 132 and y_loc = 402 then
            elsif x_loc = 612 and y_loc = 282 then
            elsif x_loc = 612 and y_loc = 242 then
            elsif x_loc = 612 and y_loc = 122 then
            elsif x_loc = 572 and y_loc = 82 then
            elsif x_loc = 532 and y_loc = 42 then
            else
                x_loc := x_loc - 40     %Allows the character to move
            end if
            Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)         %Load Background
            Pic.Draw (pic_l, x_loc, y_loc, picMerge)
            char_last_move := 3
        elsif char_move = "d" then     %-----------------------------Move Right--------------------------------------------------
            if x_loc = 612 then       %Stops character from moving off the screen on the right
                %                      Checks to see if new coordinates are 'landmarks' and cannot be moved on
            elsif x_loc = 52 and y_loc = 42 then
            elsif x_loc = 52 and y_loc = 122 then
            elsif x_loc = 52 and y_loc = 162 then
            elsif x_loc = 52 and y_loc = 202 then
            elsif x_loc = 52 and y_loc = 242 then
            elsif x_loc = 212 and y_loc = 242 then
            elsif x_loc = 492 and y_loc = 402 then
            elsif x_loc = 532 and y_loc = 282 then
            elsif x_loc = 532 and y_loc = 242 then
            elsif x_loc = 532 and y_loc = 202 then
            elsif x_loc = 532 and y_loc = 162 then
            elsif x_loc = 492 and y_loc = 122 then
            elsif x_loc = 452 and y_loc = 82 then
            elsif x_loc = 412 and y_loc = 42 then
            else
                x_loc := x_loc + 40     %Allows the character to move
            end if
            Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)         %Load Background
            Pic.Draw (pic_r, x_loc, y_loc, picMerge)
            char_last_move := 4
        elsif char_move = " "     %--------------------------------------Shoot--------------------------------------------------
                then
            if char_last_move = 1 then
                by_loc := y_loc
                bx_loc := x_loc
                fork bullet_shoot_up
            elsif char_last_move = 2 then
                by_loc := y_loc
                bx_loc := x_loc
                fork bullet_shoot_down
            elsif char_last_move = 3 then
                by_loc := y_loc
                bx_loc := x_loc
                fork bullet_shoot_left
            elsif char_last_move = 4 then
                by_loc := y_loc
                bx_loc := x_loc
                fork bullet_shoot_right
            else
            end if
        elsif char_move = "t" then     %--------------------------------Teleport------------------------------------------------
            if x_loc = 612 and y_loc = 242 then     %Checks to see if character is on the teleporter coordinates
                Pic.ScreenLoad ("tele_flash.bmp", 612, 242, picMerge)
                delay (500)
                Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)
                Pic.ScreenLoad ("tele_flash.bmp", 532, 42, picMerge)
                delay (500)
                Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)
                Pic.ScreenLoad ("top_r.bmp", 532, 42, picMerge)
                x_loc := 532
                y_loc := 42
                char_last_move := 4
            elsif x_loc = 532 and y_loc = 42 then
                Pic.ScreenLoad ("tele_flash.bmp", 532, 42, picMerge)
                delay (500)
                Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)
                Pic.ScreenLoad ("tele_flash.bmp", 612, 242, picMerge)
                delay (500)
                Pic.ScreenLoad ("m2.bmp", 50, 40, picCopy)
                Pic.ScreenLoad ("top_u.bmp", 612, 242, picMerge)
                x_loc := 612
                y_loc := 242
                char_last_move := 1
            else
            end if
        elsif char_move = "e" then     %-------------------------------Exit Level-----------------------------------------------
            if x_loc = 612 and y_loc = 122 then     %Checks to see if the character is on the exit level coordinates
                delay (1000)
                drawfillbox (33, 33, maxx - 33, maxy - 53, black)
                Font.Draw ("Level 1 Complete", 230, 300, FontID3, blue)
                delay (1000)
                Font.Draw ("Good Job", 290, 270, FontID3, blue)
                exit
            else
            end if
        else
        end if
    end loop
end char_movement



there are alot of pics needed obviously b4 it will run good....but if ucan see why the bullet.(drawin one of teh 1st 4 processes, goes to teh end of the screen and keeps erasing the character...NEVER Stopping and erasing teh bullet, and it never seems to exit the loop in the bullet drwing process..could it be somethings wrong in the process that callss the bullets to draw..... anyway tell me what u think...i still want to use this mode of "Transportation" to move the character Laughing ......thanks...
Dan




PostPosted: Sun Jan 04, 2004 8:58 pm   Post subject: (No subject)

well first of all i whould not reamend using so may forks, they are not turly need to make this progame work. you could probly do it much better if it was all in a loop and just used so many forks. it realy starts geting out of contorl when you have so many ruing at the same time.

what are you starting by_loc at? b/c you have it set so it has to be escatly 362 (or 82 for othere one) to exit if you can not add 40s on to it to get to that number it will never end.

also if this by_loc var is goable one proces is adding to it while the other is taking away. if they run at the same time it will never go anywhere.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Boarder16




PostPosted: Sun Jan 04, 2004 10:13 pm   Post subject: (No subject)

the by_loc var is started at teh y_loc of the character...the process that uses teh by cannot be called or used before the character one jsut so u know...but i c what umean..if they r both running, and by_loc is dependent on what y_loc is, and y-loc is changing....is taht what u mean... when i run the program the bullet moves fine.. but goes off teh map and goes til l teh screen stops..a nd teh character keeps disappearing.. i'll try procedures instead for the bullets if taht will help...
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: