Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
2 registered members (3run, AndrewAMD), 667 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 3 1 2 3
Re: Toggle button functions [Re: Stansmedia] #411171
11/13/12 21:05
11/13/12 21:05
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
What is the difference between function and void?


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Toggle button functions [Re: Stansmedia] #411172
11/13/12 21:12
11/13/12 21:12
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
voids means that nothing gets returned from that function.

like this:

Code:
int add_int(int a, int b) // int is the expected return-type
{
   return a + b;
}

float add_float(int a, int b) // float is the expected return-type
{
   return a + b;
}

void asdf(int a, int b) // nothing gets returned (= void)
{
   [...]
}


Last edited by Kartoffel; 11/13/12 21:17.

POTATO-MAN saves the day! - Random
Re: Toggle button functions [Re: Stansmedia] #411173
11/13/12 21:13
11/13/12 21:13
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
If I pass a global variable through a function, does it become local? This code doesn't seem to work. Sorry guys, I ask too many questions :'(
Code:
function togglevariable(var* index)
{
	if(index)
		index = OFF;
	else
		index = ON;
}

void noteoptionlogic(var number,PANEL* panel)
{
	switch (number)
	{
		case 1: togglevariable(notevisible);		break;
		case 2: togglevariable(patternvisible);				break;
		case 3: togglevariable(rootvisible);				break;
		case 4: togglevariable(notefacing);	break;
		default: error("Error in note option panel");	break;
	}	
}



I tried using return(index) but that did nothing.


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Toggle button functions [Re: Stansmedia] #411174
11/13/12 21:18
11/13/12 21:18
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
use *index = [...]; to access the var index as a pointer... wink
(...to given var or the corresponding allocated memory block, the pointer points to)

Last edited by Kartoffel; 11/13/12 21:22.

POTATO-MAN saves the day! - Random
Re: Toggle button functions [Re: Stansmedia] #411175
11/13/12 21:20
11/13/12 21:20
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Quote:
If I pass a global variable through a function, does it become local?
The global variable remains global. The argument however is local and remains local. Global = always global. Local = always local. Function parameter = local variable.

What is the function togglevariable supposed to do? index is local, you change it and the function terminates, hence the change is lost.

Please remove the star behind the var in togglevariable unless you intentionally want to pass in a pointer.


Always learn from history, to be sure you make the same mistakes again...
Re: Toggle button functions [Re: Kartoffel] #411176
11/13/12 21:21
11/13/12 21:21
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
Can you share an example? lol...


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Toggle button functions [Re: Stansmedia] #411177
11/13/12 21:24
11/13/12 21:24
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
Im trying to use togglevariable as a way to set a global variable between 0 and 1, which ive defined as ON and OFF. Instead of making functions to be called for each specific global variable.


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Toggle button functions [Re: Stansmedia] #411178
11/13/12 21:24
11/13/12 21:24
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Originally Posted By: Uhrwerk
Please remove the star behind the var in togglevariable unless you intentionally want to pass in a pointer.

for me it looks like he wants to do this:
Code:
if(index)
	index = OFF;
else
	index = ON;



POTATO-MAN saves the day! - Random
Re: Toggle button functions [Re: Stansmedia] #411179
11/13/12 21:25
11/13/12 21:25
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I think I start to understand what you want to do.

1. Leave the star behind the var as it is.
2. Change "togglevariable(notevisible);" to "togglevariable(&notevisible);". The same for the next three function calls.
3. Change
Code:
if(index)
		index = OFF;
	else
		index = ON;


to
Code:
if(*index)
		*index = OFF;
	else
		*index = ON;


4. Learn the basics! http://tutorial.3dgamestudio.net/ !


Always learn from history, to be sure you make the same mistakes again...
Re: Toggle button functions [Re: Uhrwerk] #411187
11/13/12 22:04
11/13/12 22:04
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
I'm sorry but I have to say that the pointer-tutorial only (or mostly) is about ENTITY-pointers.
String and variable-pointers for example are named but not described in there.

But you're right. The tutorials are the best start to get knowledge about all this stuff but sadly
they just barely cover all the information which are important for beginners in my opinion.

Last edited by Kartoffel; 11/13/12 22:05.

POTATO-MAN saves the day! - Random
Page 2 of 3 1 2 3

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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