Global Varibles

Need help with using DizzyAGE then look here
Post Reply
Robbington
Your Backpack is Empty
Posts: 18
Joined: Fri Dec 10, 2010 12:22 pm

Global Varibles

Post by Robbington » Fri Dec 17, 2010 10:21 pm

Me again,

Bit embaressed to ask this, as I thought I had a fairly ok understanding of programming and varibles, but I cant seem to get this to work and after reading though the GS9 section of Globals and trying a few things I thought I would ask....

What I would like is a global varible that I can store a value and add to it as the game progresses so that you can only access the final room when you have completed all the other sections.

Heres what I have done

in GameDef.gs

#def Custom_count 0

Then in the game

Robbington
Your Backpack is Empty
Posts: 18
Joined: Fri Dec 10, 2010 12:22 pm

Post by Robbington » Fri Dec 17, 2010 10:31 pm

Moron, hit the submit button by accident.

#def CUSTOM_COUNT 0

func CUSTOM_ADD() {
CUSTOM_COUNT++;
}
func CollideObject_2060_1() {
c = CUSTOM_COUNT;
if(c<=1)
{ Message0(5,3, "You are not yet worthy"); MessagePop(); return;
CUSTOM_ADD();
}
else
{ Message0(5,3, "Enter"); MessagePop(); return; }
}

The custom add function is called here just as a test.
But it doesnt seem to add to the counter, ok point and laugh...

Again, any help you can offer would be great.

Rob

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Fri Dec 17, 2010 10:44 pm

two points.

first, you can do it with the code you have, but you need to remove the 0 from the line #def CUSTOM_COUNT 0

secondly, that's not the best way of doing it, because the game doesn't save/load custom game variables that are defined in that way (you have to tell it to save/load them).

The easiest way is to use a Global variable, such as this:

Code: Select all

#def G_CUSTCOUNT		101
then use code like this (changes in red):

Code: Select all

func CUSTOM_ADD()
{
	[color="Red"]GameSet(G_CUSTCOUNT,GameGet(G_CUSTCOUNT)+1);[/color]
}

func CollideObject_2060_1()
{
	c = [color="#ff0000"]GameGet(G_CUSTCOUNT)[/color];
	if(c<=1)
	{
		Message0(5,3, "You are not yet worthy"); MessagePop(); return;
		CUSTOM_ADD();
	}
	else 
	{
		Message0(5,3, "Enter"); MessagePop(); return;
	}
}
This way, the game will automatically save and load that variable.

Of course, if you don't need the variable to be saved, the first way is easiest, but I find that most of the time, you do.

:)
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

Colin
Hard Boiled Egg
Posts: 594
Joined: Mon May 28, 2007 8:34 am
Location: Worthing, West Sussex, UK

Post by Colin » Fri Dec 17, 2010 10:53 pm

if i'm not mistaken, you never reach CUSTOM_ADD(); as you have a return; there before it. that stops the function running any further. you also don't need the other return; further down
ImageImageImage

Robbington
Your Backpack is Empty
Posts: 18
Joined: Fri Dec 10, 2010 12:22 pm

Post by Robbington » Fri Dec 17, 2010 10:58 pm

Thanks for the swift reply, Delta.

Using the code that you have provided it still doesnt seem to add to the counter. Am I doing something fundementally wrong here?

No matter how many times you walk into the collider it doesnt seem to add to the Global and the value never gets greater than 1.

Rob

Robbington
Your Backpack is Empty
Posts: 18
Joined: Fri Dec 10, 2010 12:22 pm

Post by Robbington » Fri Dec 17, 2010 10:59 pm

Bang on the money Colin,

Cheers.

Completely missed that, think I've been at this for to many hours.

Rob

delta
Hard Boiled Egg
Posts: 3965
Joined: Fri Feb 09, 2007 7:08 pm
Location: North West
Contact:

Post by delta » Fri Dec 17, 2010 11:06 pm

Colin wrote:if i'm not mistaken, you never reach CUSTOM_ADD(); as you have a return; there before it. that stops the function running any further. you also don't need the other return; further down
doh! I didn't see that. Time for bed I think...
Image

Image

"Quotes from the internet may not be genuine" - Abraham Lincoln

Post Reply