Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / types as parameters in functions

Author
Message
samqweqwe
11
Years of Service
User Offline
Joined: 7th Apr 2013
Location:
Posted: 8th Aug 2013 22:06
wondering if it was possible to make a type as a parameters for functions. it would be alot better than typeing in each value on the type

for example


how can it be done if it can be?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Aug 2013 22:19
Yes you can pass a UDT into a function, however, it's passed by value. Therefore, whatever you do to that variable will only exist within the function. You'd have to return it and assign to something else outside the scope of the function.



Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 8th Aug 2013 23:04
and one issue i had, you can not dim a udt inside a function and
give it the next function.
a faster way is giving the function the array index
but then you can handle only one array with it...
samqweqwe
11
Years of Service
User Offline
Joined: 7th Apr 2013
Location:
Posted: 9th Aug 2013 02:05
doent seem to work... i get this error:

Sprite 0 does not exist at line ... in ....agc

it is what is located at the position


the line where the error occurs is SetSpritePositionByOffset
this function is called like:


what am i doing wrong??
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Aug 2013 03:14
i can't see the source where you set .spr=
Hockeykid
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 9th Aug 2013 08:15
Quote: "doent seem to work... i get this error:"


Unfortunately, UDT's can't be returned from a function (which looks like what you're trying to do).

Sean

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Aug 2013 09:13
@Hockeykid
it seems to works, here is a example

samqweqwe
11
Years of Service
User Offline
Joined: 7th Apr 2013
Location:
Posted: 9th Aug 2013 16:19 Edited at: 9th Aug 2013 16:21
sorry
heres the UDT definition:


and heres .spr
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 9th Aug 2013 19:55
That's never going to work on Android!

Take the space out.

-- Jim DO IT FASTER, EASIER AND BETTER WITH AppGameKit FOR PASCAL
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 9th Aug 2013 20:47
UDTs can be passed by value, to and from functions. Just beware of this bug. http://code.google.com/p/agk/issues/detail?id=449&start=100

samqweqwe
11
Years of Service
User Offline
Joined: 7th Apr 2013
Location:
Posted: 9th Aug 2013 20:57
Quote: "Take the space out."


do you mean like:
?

would a better way to do this is by having an array where everything is a float eg ball#[10] insead of ball as _obj?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Aug 2013 00:52
i believe JimHawkins means the space in filename, rename and try.
ball.img = LoadImage ( "basicball.png" )
ball.spr = CreateSprite ( ball.img )

if you only have one sprite with this image you can use also ball.spr=LoadSprite("basicball.png")
samqweqwe
11
Years of Service
User Offline
Joined: 7th Apr 2013
Location:
Posted: 10th Aug 2013 14:03 Edited at: 10th Aug 2013 14:52
thanks

would it be better if ball.spr = 1 instead of ball.spr = CreateSprite? what i gather is that it is not putting values into the function

EDIT:
i may have found why i is doing it. originally i had:



where in a different file i went



where in another file


but by removing the middle function it worked



is there a way to overcome this?
peterJBE
16
Years of Service
User Offline
Joined: 11th Mar 2008
Location: Belgium
Posted: 10th Aug 2013 17:59
I am also a bit confused by the discussion about UDT´s
I think if passing by value works correctly following code should be OK. f1() can not access the first member of the UDT.


I wonder why this works as a workaround

samqweqwe
11
Years of Service
User Offline
Joined: 7th Apr 2013
Location:
Posted: 10th Aug 2013 19:06
that seems like it should work. ill try it out
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 12th Aug 2013 21:00 Edited at: 12th Aug 2013 21:00
Quote: "p1 as person"

Perhaps this doesn't work as it's not being turned into an array, whereas internally Globals are arrays.

If you're declaring new types surely you should be typing the following anyway:

Dim p1 as person


In AppGameKit, I ALWAYS create UDT's at the top of include files not in functions, and declare them in functions without error.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Aug 2013 23:27
Quote: "In AppGameKit, I ALWAYS create UDT's at the top of include files not in functions, and declare them in functions without error."

Me too. If your arrays are declared at the top of your included file (even if empty) they can be picked up anywhere.

I know it's not ideal but it works for now. I've managed to convince the team that it needs looking at and fixing (preferably before V2) but it all depends on how deep in the core code this lies as to whether it will be fixed in V1.

"Here I am trying to do some good for the world..." - Fluffy Rabbit
Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 12th Aug 2013 23:33
It's important to know that include files are just pasted under the main file during compiling, making one long main file of text, so all inside them HAS to be inside functions, and you need to call them after you use the #include command, or they never get run.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 13th Aug 2013 00:31 Edited at: 13th Aug 2013 00:31
Quote: "so all inside them HAS to be inside functions"

Not entirely true. Type defines DO NOT need to be executed in AppGameKit to be processed. Yes it's true #includes are included at the bottom of the code, but when I define them, they're in 'No Codes Land' either Between the End statement and the first function declaration, or between functions where execution never reaches. (Gotta love pre-processors!) I do however have to declare the type in executing code.

Note the difference between a define and a declare...

Define: Does not need to be stepped over.

Declare: Needs to be executed.


baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Aug 2013 10:44
@Mobiius is right actually. I always define UDT's in a relevant agc file. For example my player type is almost always declared in my player.agc file these days. I just find it easier to keep track of that way.

"Here I am trying to do some good for the world..." - Fluffy Rabbit
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 13th Aug 2013 20:33
Quote: "@Mobiius is right actually."

Don't sound so surprised! lol

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Aug 2013 23:09
Not surprised at all, you normally are right. Except when you're wrong.

"Here I am trying to do some good for the world..." - Fluffy Rabbit
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 13th Aug 2013 23:58
Never a truer word was spoken. lol

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 15th Aug 2013 06:55
There is currently a Google bug that may have been fixed in the next beta to come out. The issue is passing a UDT into a function, which then passes that UDT variable to another function. The first function can see the UDT values properly, but the second function does not.

They haven't published the beta with that fix yet. When they do, I have a project that tests it.

That might fix some of the problem.

One of the work arounds many have used is to have a global array of the UDTs and only pass in the index to be used and then use that index with the array.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-11-24 17:27:08
Your offset time is: 2024-11-24 17:27:08