Test two local types

BlitzPlus Forums/BlitzPlus Programming/Test two local types

robot(Posted 2006) [#1]
yes, its me again. i was just thining about testing two local types at the same time. Can it be done, and how?


Grey Alien(Posted 2006) [#2]
please explain more about "testing"...


robot(Posted 2006) [#3]
Testing like:

Type player
fieid x,y
end type
Type computer
field x,y
end type
;some more code
global c.computer = new computer
c\x = 100
c\y = 100
global p.player = new player
p\x = 400
p\y = 100
glolbal pimg = loadimage("where this image is located")
global cimg = lodaimage("where this image is loacted")
;evn more code
if imagescollide(pimg,p\x,p\y,0,cimg,c\x,c\y,0)
;do simething
endif

something like this, but the types aren't global


Grey Alien(Posted 2006) [#4]
what you've posted will totally work. You can't declare types as global, they are global by definition! The instances of the types you have made, c and p, are declared as global so the test you have made is totally fine unless the test occurs in a function and you have overriden p and c with some new local definitions, which would be a bit dumb.


robot(Posted 2006) [#5]
OOOOOOOOOOOOOh! That makes everything alot easier for me! Thanks Grey


robot(Posted 2006) [#6]
Waaait a second!!
In the program im doing, i tried to take out the "Global" out, but then it gives me a message when i want to test a p type field it tells me "variable must be a type".

If your wondering, i first declared the type at the begining with all of the other variables, then first tested it in the main loop. WHAT AM I DOING WRONG!!!!!!!!!!!!!


Grey Alien(Posted 2006) [#7]
So your test is in the main loop not a function are you sure of this? If it was in a function and you took global off the main p declaration, this would mean that the p in the function was not the global one but a locally created integer, and thus not a type hense the error message.


robot(Posted 2006) [#8]
Okay, i mis read my code, and it was in a function. So, can you test two types in at the same time, and if so...HOW!


WolRon(Posted 2006) [#9]
can you test two types in
This sentence fragment doesn't make sense. Try rephrasing it so that we may understand what you mean by this.


robot(Posted 2006) [#10]
Okay, what I mean is...
So, can you test two types at the same time(like i showed you in my example, but in a function), and if so, how?


WolRon(Posted 2006) [#11]
What do you mean by TEST?
Are you referring to ImagesCollide?

Of course you can. Your code already does, doesn't it? You just have to use global variables or pass the variables to the function.

MyFunc(tempvar1.type1, tempar2.type2, tempvar3.type3, etc...)


robot(Posted 2006) [#12]
What do you mean by passing the type to the function.
Tell me more about this.®


Grey Alien(Posted 2006) [#13]
Woldron pretty much said it already:

Either leave the declaration of p and c global (and why not?) or make a function where you pass in your p and c variables to be used locally in the function.

myfunction(pl.player, com.computer)
if imagescollide(pimg,pl\x,pl\y,0,cimg,com\x,com\y,0) then dostuff

;then can your function like this at any time
myfunction(p,c)


I can't make it much more simple than that.