⌂ YolkfolkThe Dizzy Fansite
Community discussion

Global Varibles

Started by Robbington on 17 December 2010 • 4,307 views

7 posts
#54855
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
👍 0
#72338
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
👍 0
#72339

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:

#def G_CUSTCOUNT 101

then use code like this (changes in red):

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

func CollideObject_2060_1()
{
	c = [color="#ff0000"]GameGet(G_CUSTCOUNT);
	if(c&lt;=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.

:smile:

👍 0
#72340
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
👍 0
#72341
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
👍 0
#72342
Bang on the money Colin,

Cheers.

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

Rob
👍 0
#72345
[quote data-userid="74" data-postid="72340"]

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

[/quote]

doh! I didn't see that. Time for bed I think...

👍 0