Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Ugh.. Cog was nearly done,---
Ugh.. Cog was nearly done,---
2004-02-27, 5:18 AM #1
Grrrrrrr... I was almost finished with this cog then the switch stops working, and I cant figure out why, everything seems to be put together correctly.

Please help me with this.. ^_^..

Code:
symbols
	message	startup
	message	arrived
	message	activated

	thing		hovercraft
	surface		switch
	flex		MoveSpeed=1.0
	sound		HoverSound
	flex		Volume=.5
	flex		mindist=10
	flex		maxdist=10
	flex		1_2=1

	int	dummy	local
	int	flag=0	local
	int	flag2=0	local
end
# ...................................................................................................
code
startup:
	SetWallCel(switch,0);
	return;
arrived:
	If(flag == 0) MoveToFrame(hovercraft, 0, MoveSpeed);
	 flag = 1;
	 flag2 = 0;
	else If(flag2 == 0) MoveToFrame(hovercraft, 9, MoveSpeed);
	 flag = 0;
	 flag2 = 1;
	Stop;
activated:
	If(GetWallCel(switch) == 0)
	{
	 call move_hc;
	}
	 else if(GetWallCel(switch) == 1)
	 {
	  call stop_move;
	 }
	return;
# ...................................................................................................
move_hc:
	dummy = PlaySoundThing(hoversound, hovercraft,volume,mindist,maxdist,0x81);
	 MoveToFrame(hovercraft, 9, movespeed);
	 SetWallCel(switch,1);
	 flag = 0;
	 flag2 = 0;
	return;
#..............................
stop_move:
	dummy = MoveToFrame(hovercraft, 0, movespeed);
	 SetWallCel(switch,0);
	 flag = 1;
	 flag2 = 1;
	return;
#..............................
end


I cant see what the problem is.. It worked fine before I added the second flag value, but I need that to make the loop stop when its suppose to, and to work when its suppose to.. ^_^//.. Please help!
"Greetings young Padawan."
2004-02-27, 5:42 AM #2
Whoa, I've never seen if blocks like this. The if blocks I know look like this:
Code:
if(condition1)
{
 code;
}
else if(condition2)
{
 code;
}
else
{
 code;
}

As far as I know, you can leave the brackets, if there is only one command in the respective code block. So this should be legal:
Code:
if(1)
 SetWallCell(switch, 1000);
else
 Print("This case never happens! So this is a complete waste...");

And yes, I know that there cannot be 1000 cels in a mat. Slap me!

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-02-27, 9:31 AM #3
Ummmm....

The Else If command will be used.. Why else would I keep it?

And, -- what was your point? lol..
"Greetings young Padawan."
2004-02-27, 9:50 AM #4
Dude, you REALLY need to get Parsec, and from the looks of it, you need to get Datamaster too. These two programs are invaluable for EVERY cogger. Get them here.

Identifiers (aka: variable names) are only valid if they start with a LETTER!!! THEY CANNOT START WITH NUMBERS!!! Therefore, 1_2 is NOT a valid identifier.
I think what Zag was saying is that you don't have some of your stuff in blocks
Code:
	If(flag == 0) MoveToFrame(hovercraft, 0, MoveSpeed);
	 flag = 1;
	 flag2 = 0;

The above code should be like the below.
Code:
	If(flag == 0)
	{ 
         	MoveToFrame(hovercraft, 0, MoveSpeed);
	 	flag = 1;
	 	flag2 = 0;
	}
	else If(flag2 == 0)
	{
		MoveToFrame(hovercraft, 9, MoveSpeed);
		flag = 0;
	 	flag2 = 1;
	}
	Stop;

You had what is called a "dangling else", which has no corresponding "if" statement. Your else-if statement will NOT work. If there is more than one command after the if, then you need a block. And indenting does not make it a block, only brackets do. If you have an else statement, it needs to come RIGHT AFTER the if block. Also, if statements ALWAYS have blocks; just because there is no brackets after it doesn't mean there's no block -- it will take the next command/statement and make it its "block". I suppose this would be called something like "implied blocks".

Try using this cog.
Code:
# Jedi_Nenshou's switch cog thingie.
# Parsed with Parsec and tidied up with Scribe.
#==============================================================#
symbols

message   startup
message   arrived
message   activated

thing     hovercraft

surface   switch

flex      MoveSpeed=1.0
flex      Volume=.5
flex      mindist=10
flex      maxdist=10
flex      one_2=1

sound     HoverSound

int       dummy           local
int       flag=0          local
int       flag2=0         local

end
#==============================================================#
code
#------------------------------------------------------
startup:
	SetWallCel(switch, 0);

Return;
#------------------------------------------------------
arrived:
	if(flag == 0)
	{
		MoveToFrame(hovercraft, 0, MoveSpeed);
		flag = 1;
		flag2 = 0;
	}
	else if(flag2 == 0)
	{
		MoveToFrame(hovercraft, 9, MoveSpeed);
		flag = 0;
		flag2 = 1;
	}

Stop;
#------------------------------------------------------
activated:
	if(GetWallCel(switch) == 0) call move_hc;
	else if(GetWallCel(switch) == 1) call stop_move;

Return;
#------------------------------------------------------
move_hc:
	dummy = PlaySoundThing(HoverSound, hovercraft, Volume, mindist, maxdist, 0x81);
	MoveToFrame(hovercraft, 9, MoveSpeed);
	SetWallCel(switch, 1);
	flag = 0;
	flag2 = 0;

Return;
#------------------------------------------------------
stop_move:
	MoveToFrame(hovercraft, 0, MoveSpeed);
	SetWallCel(switch, 0);
	flag = 1;
	flag2 = 1;

Return;
#------------------------------------------------------
end

btw, I'm not yelling at you or anything; the caps are just to emphasize my points. [http://forums.massassi.net/html/smile.gif]

------------------
I am Darth Slaw.
The Dark Lord of the Sith,
And part of the Nightfire mod team

[This message has been edited by Darth Slaw (edited February 27, 2004).]
May the mass times acceleration be with you.
2004-02-27, 10:08 AM #5
Yeah. Try Slaw's cog.

[Edit]
Excerpt of an ancient COG Document called COG101.txt:
Code:
Following the list of possible if statement variations:

simple, one command per block
-----------------------------

if(condition)
command;

Executes "command", if "condition" is true.

with else, one command per block
--------------------------------

if(condition)
command1;
else
command2;

Executes "command1", if "condition" is true, otherwise executes "command2".

with else ifs, one command per block
------------------------------------

if(condition1)
command1;
else if(condition2)
command2;
else if(condition3)
command3;
.
.
.

Executes "command1", if "condition1" is true, otherwise checks "condition2". Executes "command2", if "condition2" is true, otherwise checks "condition3", and so on.

with else ifs and else, one command per block
---------------------------------------------

if(condition1)
command1;
else if(condition2)
command2;
else if(condition3)
command3;
.
.
.
else
commandx;

Executes "command1", if "condition1" is true, otherwise checks "condition2". Executes "command2", if "condition2" is true, otherwise checks "condition3", and so on. Executes "commandx", if no conditions are true.

all the same **** again, multiple commands per block
----------------------------------------------------

Apply brackets to "blocks" like this:

{
block;
}

A "block" is a list of commands. Example:

if(condition)
{
command1;
command2;
.
.
.
commandx;
}
else
commandy;

Executes all the commands between the brackets, if "condition" is true. Otherwise executes "commandy".


------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

[This message has been edited by zagibu (edited February 27, 2004).]
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-02-27, 10:11 AM #6
lol.. I know you arnt yelling at me, caps show importance, which I use a lot.

And, the format I used, the way my blocks were set, is th same way most of the cogs in JK are.. The Comp. made ones. Thats why I used that type of format, but perhaps I read it incorrectly.. ^_^...

Thanks.. I'm not going to -- Copy.. lol.. I hate that word.. But Ill do what it is you told me, and Ill post back when I have tested.
"Greetings young Padawan."
2004-02-27, 10:15 AM #7
Oh yeah, before I forget, where can I get thoughs programs?
"Greetings young Padawan."
2004-02-27, 10:21 AM #8
Yes!.. Worked.. ^_^... Thanks a lot dude...

Perhaps someone can help me with yet Another problem.. When I set the stop sound at arival -- it doesnt stop the sound.. How should I use the command, with the above code?
"Greetings young Padawan."
2004-02-27, 10:34 AM #9
You might try a StopSound(dummy, 0);. I think the first param of the verb has to be a sound channel, so this might work. But it would be easier to use a .snd file anyway...

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-02-27, 11:21 AM #10
lol..

I already figured it out,.. I was using the StopSound(); command, but, for some reason it wasnt working, it just brought the vol. level down, and sounded really distorted.. But that was because of the way everything was set up, which I just changed, so now it works.. ^_^...

lol.. Where do I get thoughs programs?
"Greetings young Padawan."
2004-02-27, 12:49 PM #11
http://www.geocities.com/sabersdomain/

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-02-27, 2:18 PM #12
I can't believe that I missed a shameless plug for SaberMaster's DataMaster (aka - The COG BIBLE) [http://forums.massassi.net/html/biggrin.gif]

DataMaster combined with Parsec are the only COG essentials that you'll ever need - every other COG related tool/utility/program is entirely optional, but once you become proficient in coding COG, you'll find this out for yourself [http://forums.massassi.net/html/smile.gif].

The DataMaster should be your first port of call, invaluable for all the reference information contained; Parsec is exceptionally useful for debugging your "newly-written" scripts and, when coding late at night, is useful for picking up the compulsory missing ";" [http://forums.massassi.net/html/wink.gif]

Hope this information helps [http://forums.massassi.net/html/biggrin.gif]

-Jackpot

------------------
"lucky_jackpot is the smily god..." - gothicX

"Life is mostly froth and bubble,
But two things stand in stone,
Kindness in another's trouble,
Courage in your own"
("Ye Wearie Wayfarer" - by Adam Lindsay Gordon)
"lucky_jackpot is the smily god..." -gothicX
"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
- "Ye Wearie Wayfarer"
|| AI Builder: compatible with both JK & MotS || My website ||

↑ Up to the top!