Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, 7th_zorro), 1,203 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
function vs. void #451372
05/05/15 01:19
05/05/15 01:19
Joined: Apr 2015
Posts: 9
Ontario, Canada
K
kornstar Offline OP
Newbie
kornstar  Offline OP
Newbie
K

Joined: Apr 2015
Posts: 9
Ontario, Canada
Hello everyone, I am fairly new to programming and 3dgs and have been looking through the workshops and many contributed scripts to learn how to make games using this software. I have noticed that many people use void when creating a function and I have been told that void is the same thing as function except that you are not passing any variables through it.

I was just wondering if there are any other differences (or advantages) to using void as opposed to function.

any info on this would be greatly appreciated.

Re: function vs. void [Re: kornstar] #451373
05/05/15 02:01
05/05/15 02:01

M
Malice
Unregistered
Malice
Unregistered
M



Please read this thread from a few weeks ago. I found it with the forum search.

http://www.opserver.de/ubb7/ubbthreads.p...true#Post449452

Mal

Re: function vs. void [Re: ] #451375
05/05/15 02:25
05/05/15 02:25
Joined: Apr 2015
Posts: 9
Ontario, Canada
K
kornstar Offline OP
Newbie
kornstar  Offline OP
Newbie
K

Joined: Apr 2015
Posts: 9
Ontario, Canada
Thank you very much Malice, I had began to look through some threads to try to figure this out but quickly became overwhelmed by the amount of info that can be found on this forum.

As I am a Noob to this I will have to re-read the thread a few times to properly understand it but it looks like it has all the info I need.

Again, thanks for your help laugh

Re: function vs. void [Re: kornstar] #451376
05/05/15 02:39
05/05/15 02:39

M
Malice
Unregistered
Malice
Unregistered
M



Your welcome,
And Welcome to the forum...

Re: function vs. void [Re: ] #451377
05/05/15 03:24
05/05/15 03:24
Joined: Apr 2015
Posts: 9
Ontario, Canada
K
kornstar Offline OP
Newbie
kornstar  Offline OP
Newbie
K

Joined: Apr 2015
Posts: 9
Ontario, Canada
Thanks, I look forward to bombarding you all with my noob questions, but I'll try running searches first to avoid double posting questions (like this time).

Re: function vs. void [Re: kornstar] #451393
05/05/15 14:44
05/05/15 14:44
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline
Serious User
Happy Birthday DLively  Offline
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
Originally Posted By: MasterQ32
function is just an alias for var.
Both are defined with as fixed:
Code:
typedef fixed var;
typedef fixed function;


So you can actually do this:
Code:
function a, b;
a = 10;
b = 20;
printf("%f", a + b);



Regards


A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: function vs. void [Re: DLively] #451396
05/05/15 15:42
05/05/15 15:42
Joined: Apr 2015
Posts: 9
Ontario, Canada
K
kornstar Offline OP
Newbie
kornstar  Offline OP
Newbie
K

Joined: Apr 2015
Posts: 9
Ontario, Canada
Thanks DLively, I had read that post from your original thread (thanks to the link provided by Malice).

if I understand that statement correctly then I should also be able to go

Code:
var example(){
insert function code here;
}



and it would have the same effect as

Code:
function example(){
insert function code here;
}



and I should be able to call the first example the same way as the second

Code:
example();



is that right or am I not understanding this properly?

Re: function vs. void [Re: kornstar] #451397
05/05/15 15:55
05/05/15 15:55
Joined: Apr 2005
Posts: 1,988
Canadian, Eh
DLively Offline
Serious User
Happy Birthday DLively  Offline
Serious User

Joined: Apr 2005
Posts: 1,988
Canadian, Eh
yes, exactly laugh

and void doens't return values
Quote:
void cant return anything aka 0xC3 in assembler

Last edited by DLively; 05/05/15 15:57.

A8 Pro 8.45.4
YouTube: Create Games For Free
Free Resources: www.CGForFree.com
Re: function vs. void [Re: DLively] #451399
05/05/15 16:19
05/05/15 16:19
Joined: Apr 2015
Posts: 9
Ontario, Canada
K
kornstar Offline OP
Newbie
kornstar  Offline OP
Newbie
K

Joined: Apr 2015
Posts: 9
Ontario, Canada
I haven't run into a situation yet where I have needed to return any values from a function, and to be honest I'm still not really sure how the whole "return" thing works, but I'm sure that I will eventually need to do that and I will have more specific questions when that time comes.

Just out of curiosity... what is 0xC3?.. As I said I'm still very new to this and have a lot to learn.

Thanks again for the help laugh

Re: function vs. void [Re: kornstar] #451402
05/05/15 16:37
05/05/15 16:37
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: kornstar
Just out of curiosity... what is 0xC3?..

It honestly doesn't matter, it's just Chaos trying to sound smart and then ending up mixing multiple buzzwords that have no relation to each other.

If you want to know the full story in short, your code gets compiled down to machine code at some point (usually with various intermediate steps from high level C to machine code). The CPU will then execute the machine code, as that is the one it understands, note though that there is not necessarily a direct conversion between high level C concepts and what the CPU will eventually see. In any case though, the machine code is, well, machine dependent, and the code the CPU can execute is called the ISA, short for instruction set architecture. Your normal desktop CPU that runs Windows runs the x86 or x86-64 ISA, which is an ISA that has grown since the Intel 80386 (released 1986). One of the many instructions the ISA offers is the return instruction which returns back to the caller, and encoded in hex it's 0xc3. It matters fuck all in your every day coding, so you might as well forget everything about it.

Now, for void vs everything else. void is just saying that the function won't return any value, whereas for example int means the function will return an int to the caller.

This is tied to return only insofar that you use return to return a value to the caller and a function that returns anything but void has to have a return with a value somewhere to not be malformed. Of course this would break a lot of badly written Lite-C functions so the compiler doesn't enforce it. You can use return in void functions too though, it just won't return anything. But it can be used to pre-maturely leave a function based on a condition or whatever.

When your function reaches the last closing bracket, there is an implicit return from it.

There is no advantage of one over the other. Some dipshits used to spread the rumour that one is faster than the other, but luckily this hasn't come up in the more recent past. If you find a reference to this anywhere though, just remember that it's absolute bullshit and don't believe anything the author has to say. The real difference is that you provide intent. If you intent to return an int, then declare your function as returning an int. If you don't return anything, use void. That way the compiler can help you out (if it weren't for the fact that it's shit) and you can get an idea of what the function will do based on just looking at the functions signature.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1