Posted: Tue Dec 15, 2009 4:14 pm Post subject: How to take information from procedures and put it in another procedure/ process
What is it you are trying to achieve?
I want to take infromation from a procedure or a process and be able to put the same information in
a next procedure/process Ex: an animation
What is the problem you are having?
I don't know how to do it. (The pervasive variables didn't work because it's an
animation, so it continously changes coordinates)
I know the code is long, 993 lines to be exact. But I just want to know how to take a sprites movement and
put it in a new procedure. Because i want my Sprite.Animate (in the background process)
to collided with my mario and luigi sprites in (procedure sprites)
If this sounds confusing, tell me and I'll try to explain it better
% start of mario's attacks %---------------------------
% mario hammer - right
mariohammerr :=Pic.FileNew("mariohammerR.bmp")
mar :=Sprite.New(mariohammerr) % mario hammer - left
mariohammerl :=Pic.FileNew("mariohammerL.bmp")
mar1 :=Sprite.New(mariohammerl) % mario hammer continued 2 - right
mariohammerr2 :=Pic.FileNew("mariohammerR2.bmp")
mar2 :=Sprite.New(mariohammerr2) % mario hammer continued 2 - left
mariohammerl2 :=Pic.FileNew("mariohammerL2.bmp")
mar3 :=Sprite.New(mariohammerl2) % mario hammer continued 3 - right
mariohammerr3 :=Pic.FileNew("mariohammerR3.bmp")
mar4 :=Sprite.New(mariohammerr3) % mario hammer continued 3 - left
mariohammerl3 :=Pic.FileNew("mariohammerL3.bmp")
mar5 :=Sprite.New(mariohammerl3) % mario hammer continued 4 - right
mariohammerr4 :=Pic.FileNew("mariohammerR4.bmp")
mar6 :=Sprite.New(mariohammerr4) %mario hammer continued 4 - left
mariohammerl4 :=Pic.FileNew("mariohammerL4.bmp")
mar7 :=Sprite.New(mariohammerl4) % mario smash - right
mariosmashr :=Pic.FileNew("mariosmashR.bmp")
mar8 :=Sprite.New(mariosmashr) % mario smash - left
mariosmashl :=Pic.FileNew("mariosmashL.bmp")
mar9 :=Sprite.New(mariosmashl) % mario smash finish - right
mariosmashfr :=Pic.FileNew("mariosmashfR.bmp")
mar10 :=Sprite.New(mariosmashfr) % mario smash finish - left
mariosmashfl :=Pic.FileNew("mariosmashfL.bmp")
mar11 :=Sprite.New(mariosmashfl)
% Mario end of hammer attacks % -------------------------------------------
% start of Mario Super Smash %-------------------------------------------- var mariosupersmashr, mariosupersmashl :int var super, super1 :int
% Start of Mario Smash - right
mariosupersmashr :=Pic.FileNew("mariosupersmashR.bmp")
super :=Sprite.New(mariosupersmashr) % Start of Mario Smash - left
mariosupersmashl :=Pic.FileNew("mariosupersmashL.bmp")
super1 :=Sprite.New(mariosupersmashl)
% Mario Tunnel %-------------------------------------------- var mariotunnel, mariotunnel2, mariotunnel3, marioblank :int var martun, martun1, martun2, martun3 :int
% Mario tunnel 1
mariotunnel :=Pic.FileNew("mariotunnel.bmp")
martun :=Sprite.New(mariotunnel) % Mario tunnel 2
mariotunnel2 :=Pic.FileNew("mariotunnel2.bmp")
martun1 :=Sprite.New(mariotunnel2) % Mario tunnel 3
mariotunnel3 :=Pic.FileNew("mariotunnel3.bmp")
martun2 :=Sprite.New(mariotunnel3) % Mario black
marioblank :=Pic.FileNew("marioblank.bmp")
martun3 :=Sprite.New(marioblank)
% Mario collision var mariocollision, mariofall :int var fall, fall1 :int
% Mario collision - with Luigi
mariocollision :=Pic.FileNew("mariocollision.bmp")
fall :=Sprite.New(mariocollision) % Mario fall
mariofall :=Pic.FileNew("mariofall.bmp")
fall1 :=Sprite.New(mariofall)
% luigi start drawing %-------------------------------- % luigi basic stepping sprites var luigistandr, luigistandl, luigiwalkr, luigiwalkl, luigiwalkr2, luigiwalkl2 :int var l, l1, l2, l3, l4, l5 :int
% luigi stand - right
luigistandr :=Pic.FileNew("luigistandR.bmp")
l :=Sprite.New(luigistandr) % luigi stand - left
luigistandl :=Pic.FileNew("luigistandL.bmp")
l1 :=Sprite.New(luigistandl) % luigi walk - right
luigiwalkr :=Pic.FileNew("luigiwalkR.bmp")
l2 :=Sprite.New(luigiwalkr) % luigi walk - left
luigiwalkl :=Pic.FileNew("luigiwalkL.bmp")
l3 :=Sprite.New(luigiwalkl) % luigi walk 2 - right
luigiwalkr2 :=Pic.FileNew("luigiwalkR2.bmp")
l4 :=Sprite.New(luigiwalkr2) % luigi walk 2 - left
luigiwalkl2 :=Pic.FileNew("luigiwalkL2.bmp")
l5 :=Sprite.New(luigiwalkl2)
% Start of Luigi's hammering %-------------------------------------- var luigihammerr, luigihammerl, luigihammerr2, luigihammerl2, luigihammerr3, luigihammerl3 :int var luigihammerr4, luigihammerl4, luigihammerfinishr, luigihammerfinishl :int var ham, ham1, ham2, ham3, ham4, ham5, ham6, ham7, ham8, ham9 :int
% luigi start hammering - right
luigihammerr :=Pic.FileNew("luigihammerR.bmp")
ham :=Sprite.New(luigihammerr) % luigi start hammering - left
luigihammerl :=Pic.FileNew("luigihammerL.bmp")
ham1 :=Sprite.New(luigihammerl) % luigi hammer continued 2 - right
luigihammerr2 :=Pic.FileNew("luigihammerR2.bmp")
ham2 :=Sprite.New(luigihammerr2) % luigi hammer continued 2 - left
luigihammerl2 :=Pic.FileNew("luigihammerL2.bmp")
ham3 :=Sprite.New(luigihammerl2) % luigi hammer continued 3 - right
luigihammerr3 :=Pic.FileNew("luigihammerR3.bmp")
ham4 :=Sprite.New(luigihammerr3) % luigi hammer continued 3 - left
luigihammerl3 :=Pic.FileNew("luigihammerL3.bmp")
ham5 :=Sprite.New(luigihammerl3) % luigi hammer continued 4 - right
luigihammerr4 :=Pic.FileNew("luigihammerR4.bmp")
ham6 :=Sprite.New(luigihammerr4) % luigi hammer continued 4 - left
luigihammerl4 :=Pic.FileNew("luigihammerL4.bmp")
ham7 :=Sprite.New(luigihammerl4) % luigi hammer finished - right
luigihammerfinishr :=Pic.FileNew("luigihammerfinishR.bmp")
ham8 :=Sprite.New(luigihammerfinishr) % luigi hammer finished - left
luigihammerfinishl :=Pic.FileNew("luigihammerfinishL.bmp")
ham9 :=Sprite.New(luigihammerfinishl)
% end of luigi hammer %-------------------------------
% start of luigi sit %------------------------------- var luigisitr, luigisitl :int var sit, sit1 :int
% luigi sitting - right
luigisitr :=Pic.FileNew("luigisitR.bmp")
sit :=Sprite.New(luigisitr) % luigi sitting - left
luigisitl :=Pic.FileNew("luigisitL.bmp")
sit1 :=Sprite.New(luigisitl)
% end of luigi sit %--------------------------------
% start of luigi jump var luigijumpr, luigijumpl :int var jump, jump1 :int
% luigi jumping - right
luigijumpr :=Pic.FileNew("luigijumpR.bmp")
jump :=Sprite.New(luigijumpr) % luigi jumping - left
luigijumpl :=Pic.FileNew("luigijumpL.bmp")
jump :=Sprite.New(luigijumpl)
% start of luigi tunnel var luigitunnel, luigitunnel2, luigitunnel3, luigiblank :int var tun, tun1, tun2, tun3 :int
% Luigi tunnel 1
luigitunnel :=Pic.FileNew("luigitunnel.bmp")
tun :=Sprite.New(luigitunnel) % Luigi tunnel 2
luigitunnel2 :=Pic.FileNew("luigitunnel2.bmp")
tun1 :=Sprite.New(luigitunnel2) % Luigi tunnel 3
luigitunnel3 :=Pic.FileNew("luigitunnel3.bmp")
tun2 :=Sprite.New(luigitunnel3) % Luigi Blank
luigiblank :=Pic.FileNew("luigiblank.bmp")
tun3 :=Sprite.New(luigiblank)
% for mario direction var sprgen :boolean
sprgen :=true if sprgen =truethen Sprite.ChangePic(spr, mariostandr) elsif sprgen =falsethen Sprite.ChangePic(spr, mariostandl) endif
% for luigi var sprbol :boolean
sprbol :=true if sprbol =truethen Sprite.ChangePic(l, luigistandr) elsif sprbol =falsethen Sprite.ChangePic(l, luigistandl) endif
const ground :=10 var gravity :int:=2 const runspeed :=5 var chars :arraycharofboolean var posx, posy :int var x, y :int var velx, vely :int var vexx, veyy :int
posx :=21
posy :=10
velx :=0
vely :=0
vexx :=0
veyy :=0
x :=400
y :=10
loop delay(100) locate(1, 15) Text.Color(0) put"-Use the left and right arrow keys" locate(2, 15) put"or the numpad(4 and 6) to move Mario" delay(100) locate(3, 15) Text.Color(13) delay(100) put"-Press the enter key to use your hammer"..
locate(4, 15) delay(100) put"-Press the shift key to do a super hammer attack"..
locate(5, 15) Text.Color(76) delay(100) put"- press the up arrow or 8 on the numpad"..
locate(6, 15) delay(100) put"to jump. Also press which direction you want to go"..
locate(7, 15) Text.Color(48) delay(100) put"to crouch press down or 5 on the numpad"..
locate(8, 15) delay(100) put"-to enter the tunnel press the control key"..
locate(16, 1) Text.Color(103) delay(100) put"-To move Luigi use 'A' and 'D'"..
locate(17, 1) Text.Color(40) delay(100) put"-To make Luigi jump, press 'W' + ('A' or 'D')"..
locate(18, 1) Text.Color(64) delay(100) put"-To use the hammer click 'B'"..
locate(19, 1) Text.Color(36) delay(100) put"-To sit down, press 'S' "..
locate(20, 1) delay(100) put"-To go in the tunnel, press 'N'"..
locate(13, 1) Text.Color(0) delay(100) put"To go back to the menu, press M" loop getch(chars) if chars =("m")then
mainmenu
endif endloop endloop endif
varpervasive mariostandr, mariostandl, mariowalkr, mariowalkl, mariowalkr2, mariowalkl2 :int var mariocfr, mariocfl, mariocfr2, mariocfl2, tunnel, platform :int var spr, spr1, spr2, spr3, spr4, spr5, spr6, spr7, spr8, spr9, spr10, spr11 :int var mariojumpr, mariojumpl, mariojumpr2, mariojumpl2, mariojumpr3, mariojumpl3 :int var sprite, sprite1, sprite2, sprite3, sprite4, sprite5 :int %mario attacks var mariohammerr, mariohammerl, mariohammerr2, mariohammerl2, mariohammerr3, mariohammerl3 :int var mariohammerr4, mariohammerl4, mariosmashr, mariosmashl, mariosmashfr, mariosmashfl :int var mar, mar1, mar2, mar3, mar4, mar5, mar6, mar7, mar8, mar9, mar10, mar11 :int
% mario standing -right
mariostandr :=Pic.FileNew("mariostandR.bmp")
spr :=Sprite.New(mariostandr) % mario standing -left
mariostandl :=Pic.FileNew("mariostandL.bmp")
spr1 :=Sprite.New(mariostandl) % mario start walk -right
mariowalkr :=Pic.FileNew("mariowalkR.bmp")
spr2 :=Sprite.New(mariowalkr) % mario start walk - left
mariowalkl :=Pic.FileNew("mariowalkL.bmp")
spr3 :=Sprite.New(mariowalkl) % mario continue walk - right
mariowalkr2 :=Pic.FileNew("mariowalkR2.bmp")
spr4 :=Sprite.New(mariowalkr2) % mario continue walk - left
process luigimenu
var luigistandr, luigistandl, luigiwalkr, luigiwalkl, luigiwalkr2, luigiwalkl2 :int var l, l1, l2, l3, l4, l5 :int
% luigi stand - right
luigistandr :=Pic.FileNew("luigistandR.bmp")
l :=Sprite.New(luigistandr) % luigi stand - left
luigistandl :=Pic.FileNew("luigistandL.bmp")
l1 :=Sprite.New(luigistandl) % luigi walk - right
luigiwalkr :=Pic.FileNew("luigiwalkR.bmp")
l2 :=Sprite.New(luigiwalkr) % luigi walk - left
luigiwalkl :=Pic.FileNew("luigiwalkL.bmp")
l3 :=Sprite.New(luigiwalkl) % luigi walk 2 - right
luigiwalkr2 :=Pic.FileNew("luigiwalkR2.bmp")
l4 :=Sprite.New(luigiwalkr2)
luigiwalkl2 :=Pic.FileNew("luigiwalkL2.bmp")
l5 :=Sprite.New(luigiwalkl2)
Please specify what version of Turing you are using
4.1.1
Sponsor Sponsor
Tony
Posted: Tue Dec 15, 2009 6:44 pm Post subject: RE:How to take information from procedures and put it in another procedure/ process
That... a lot of code. You might want to invest some time into getting familiar with arrays and for-loops.
I'm not sure what you are asking about. From the title I could try to guess that it's about functions (procedures that return values that you can use elsewhere), but I suspect that you are just not making yourself clear.
P.S. When your game starts crashing and telling you that you are out of available picture IDs, or something along those lines, you might learn not to load the _same_ images inside a loop. Or at least of Pic.Free
Posted: Wed Dec 16, 2009 8:28 am Post subject: RE:How to take information from procedures and put it in another procedure/ process
your code is really long, and not built right at all. I don't have time to look it over right now, but if you send me the pics with the program I can help you out with it in my period 3 class today.
For now listen to what tony said about looking up arrays and for loops, I'm definetly going to use them to help you out so you should know them.
I don't quite get what your asking though because as long as a variable is global (not declared within a procedure) then anything can use the variable at any time within your code.
Also using processes is a bad thing 99.9999% of the time, you might want to investigate whether you need them in seperate processes or not
drummaboy
Posted: Wed Dec 16, 2009 12:08 pm Post subject: Re: How to take information from procedures and put it in another procedure/ process
Posted: Wed Dec 16, 2009 12:12 pm Post subject: RE:How to take information from procedures and put it in another procedure/ process
And what I'm trying to say is that.
I have a sprite animation (in process background) and it works fine and all.
But I have my moveable characters in a procedure called "procedure sprites"
how do I make it so that my characters can collided with the animation?
I know how to make a varibale global but the sprite keeps on moving so then the x distance is constantly changing.
So how can I get it so that I can detect the movement of my sprite and make it interact with luigi and mario
mirhagk
Posted: Wed Dec 16, 2009 12:32 pm Post subject: RE:How to take information from procedures and put it in another procedure/ process
as long as the x position is in some sort of variable (which it should be) and you know collision detection then it shouldn't be difficult at all
drummaboy
Posted: Wed Dec 16, 2009 1:30 pm Post subject: RE:How to take information from procedures and put it in another procedure/ process
it is. but the x continues to change position. and I want them to collided but they're in 2 different procedures. So I need to do something to detect the movement of my enemy and bring that information and put in in my other procedure
drummaboy
Posted: Wed Dec 16, 2009 4:21 pm Post subject: Re: How to take information from procedures and put it in another procedure/ process
also,. I searched up arrays, but I don't know how they could helo me out
Sponsor Sponsor
mirhagk
Posted: Wed Dec 16, 2009 4:27 pm Post subject: RE:How to take information from procedures and put it in another procedure/ process
you could store the pictures in arrays (one for each character). Also store the sprites in arrays. instead of
if chars (KEY_SHIFT)and sprgen =truethen for i:1..5 Sprite.ChangePic(spr, mario(i)) delay(60) endfor endif
it will make your code MUCH shorter and ALOT easier to maintain
drummaboy
Posted: Wed Dec 16, 2009 4:29 pm Post subject: Re: How to take information from procedures and put it in another procedure/ process
wow ... it's much shorter but can you explain what you did?? How did you make it so that it can detect what sprites I want to change it to?
TheGuardian001
Posted: Wed Dec 16, 2009 4:42 pm Post subject: Re: How to take information from procedures and put it in another procedure/ process
He made it into an array. It's basically a collection of variables. We have a nice tutorial on them right over here.
mirhagk
Posted: Wed Dec 16, 2009 4:46 pm Post subject: RE:How to take information from procedures and put it in another procedure/ process
check out the linked tutorial. do a few random programs to get the hang of arrays. Then look for every opportunity you get to use them. Anywhere you see similar code being run you can use for loops and arrays.
drummaboy
Posted: Wed Dec 16, 2009 4:47 pm Post subject: RE:How to take information from procedures and put it in another procedure/ process
How would I do it with sprites though? Like I see the code but I don't understand how I'd get the pictures in the array
mirhagk
Posted: Wed Dec 16, 2009 4:53 pm Post subject: RE:How to take information from procedures and put it in another procedure/ process
just load the pictures normally except reference the array like the following example