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 / Functon help

Author
Message
Joshua A
12
Years of Service
User Offline
Joined: 19th Feb 2012
Location:
Posted: 1st Mar 2012 03:43
How do i call a function without pausing the entire program.

like once I call a function before the main do loop, that part of the program is never reached

unless I do something like this:



It seems to much to have to do this on large scale
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 1st Mar 2012 07:35
Quote: "How do i call a function without pausing the entire program."

Firstly, you need to know the difference between a function call (using the function) and a function declaration (making the function). What you have in your code snippet is a function declaration. These are typically put at the back of the code and shouldn't ever be 'run into'. In other words, placed after the program exit code. To use a function, you simply call its name and insert any necessary parameters.

When a function is called, the program will execute whatever code is contained within that function and so, depending on the code, will not necessarily, pause your program.

A small example:


Joshua A
12
Years of Service
User Offline
Joined: 19th Feb 2012
Location:
Posted: 1st Mar 2012 18:55
what if i need to call two separate functions that both have a do loop.
bitJericho
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 1st Mar 2012 19:06
agk is procedural. That means only one thing can run at a time. It's not multi-threaded, which means two things could run at a time.

This means, if you need 2 things happening at once, you must simulate that, because you can't actually do it at the same time.

So you could combine the two functions into one with one do/loop. You could call specific functions when a specific time is reached, etc. If you have a specific problem, perhaps we could give you an answer.

Joshua A
12
Years of Service
User Offline
Joined: 19th Feb 2012
Location:
Posted: 1st Mar 2012 23:15
So would something like this work. By that I mean I know it works but may not be the best option.

Quote: "
//sompthing.agc

function sompthimg ()
do
//code
goto _location
loop
endfunction




//main.agc
#include sompthing.agc

_location:
do
//code
sompthimg ()
loop
"


Iv tested this out and it does word but i fear that its not memory efficient
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 2nd Mar 2012 01:12 Edited at: 2nd Mar 2012 01:22
Not memory efficient is an understatement, that code will bleed all the memory from any system.

There are all sorts of problems there.

1) The code between "goto _location" and "#include sompthing.agc" will never be run so may as well not be there
2) You define a function at the start of a program, this should really be at the end.
3) You start a loop within a function and then abruptly exit both with a goto
4) You start another loop and then abruptly end that by calling the function you just jumped from.

From here on, you keep starting loops and recalling functions.

The system tries to keep track of all these things you start so that it knows where to go back to, but you never end a loop or leave a function properly.

It may appear to work, but you'll fill up the stack in a flash and will probably run out of memory.

If my dog wrote code like that, it would get a newspaper across the nose.

Seriously, tell us what you're trying to do and we'll try to help.
Joshua A
12
Years of Service
User Offline
Joined: 19th Feb 2012
Location:
Posted: 2nd Mar 2012 03:05
I'm trying to call set up a level and a player. Both the player and level have separate functions and they both have to run at the same time.

both functions have a do loop to keep track of everything, but as said before That is not possible
Marl
12
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 2nd Mar 2012 04:03 Edited at: 2nd Mar 2012 04:05
You can use multiple loops, but I don't think that is what you need in this case.

As Jerico2day pointed out, everything is done in sequence, you simply can't do more than one thing at the same time.

But it all happens so fast that the user would never know this.

Here's the general layout that I use.

This is a very simple example, but it should give you an idea.

Think of each function as a task to be performed. As long as you call each one in the main loop, everything will be fine.

Each function does it's job and when it gets to the "endfunction" instruction, it returns to where it was called in the main loop.

At the end of the loop when the sync() is called, all the changes for that loop are updated to the screen and this is what the user sees.

In most cases, multi-tasking is an illusion. Not just with AppGameKit, but with computers in general.

Login to post a reply

Server time is: 2024-05-02 08:12:44
Your offset time is: 2024-05-02 08:12:44