|
2 registered members (3run, AndrewAMD),
667
guests, and 1
spider. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
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
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
voids means that nothing gets returned from that function. like this:
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
OP
Serious User
|
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 :'(
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.
|
|
|
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
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
use *index = [...]; to access the var index as a pointer...  (...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
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
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: Stansmedia]
#411178
11/13/12 21:24
11/13/12 21:24
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
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:
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
Expert
|
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(¬evisible);". The same for the next three function calls. 3. Change
if(index)
index = OFF;
else
index = ON;
to
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
Expert
|
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
|
|
|
|