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 → dadgum
dadgum
2005-01-16, 11:57 AM #1
I'm new at this, and I think this cog looks right, but it doesn't work. Any suggestions?

Code:
# Jedi Knight Cog Script
#
# floorclear.COG
# Controlls thrust in sector 22
# Lets the player fall back down the lift tube 
#
# This Cog is Not supported by LucasArts Entertainment Co

symbols
message	startup
message	activated

surface	trigswitch #the switch
surface	floor #the floor to be opened
sound		beep #the sound played after the switch is switched


end

# ========================================================================================

code

startup:
SetSectorThrust(22,0/0/1,10);	#Starts the thrust in sector 22

activated:
SetAdjoinFlags(floor,0x2);		#sets the floor as passable
SetSectorThrust(22,0/0/1,-1);	#turns off thrust in sector 22
PlaySound(beep);			#plays a sound
Sleep(10);				#waits 10 seconds

SetAdjoinFlags(floor,0x1);		#turns the floor back on
SetSectorThrust(22,0/0/1,10);	#turns the thrust back on
# ........................................................................................

end
I've got a website. It's at Geocities because I'm too cheap to get my own site.
2005-01-16, 12:15 PM #2
I think the 0/0/1 format is not valid in the code section. Use '0 0 1' format instead.

By the way, to turn off thrust, use:
SetSectorThrust(22, '0 0 1', 0);
(The -1 in the original line will reverse the thrust direction.)

:)
2005-01-16, 12:25 PM #3
Made some changes (everything green is modified code)
btw, thx Zeq -- I didn't notice that the first time around :)
Code:
# Jedi Knight Cog Script
#
# floorclear.COG
# Controlls thrust in sector 'sec'
# Lets the player fall back down the lift tube 
#
# This Cog is Not supported by LucasArts Entertainment Co

symbols
message		startup
message		activated


        sector		sec		#sector with the thrust
int		active=0	local
    
surface		trigswitch	#the switch
surface		floor		#the floor to be opened
sound		beep		#the sound played after the switch is switched


end

#  ==================================================

code

startup:
	SetSectorThrust(
        sec
    ,
        '0/0/1'
    ,10);		#Starts the thrust in sector
	
        return;
    

activated:
	
        if(active) return;			#only activate once at a time
	if(GetSenderRef() != trigswitch) return;
	active = 1;				#activated; don't allow another activation
    
	SetAdjoinFlags(floor,0x2);		#sets the floor as passable
	SetSectorThrust(
        sec
    ,
        '0/0/1'
    ,-1);		#turns off thrust in sector
	
        PlaySoundLocal(beep, 1.0, 0.0, 0x0);
    	#plays a sound
	Sleep(10);				#waits 10 seconds

	SetAdjoinFlags(floor,0x1);		#turns the floor back on
	SetSectorThrust(
        sec
    ,
        '0/0/1'
    ,10);		#turns the thrust back on
	
        active = 0;			#not active anymore
	return;
    
# .....................................................................

end

Main points I have to make:
  1. You need to have 'return;' s (or 'stop;' s) after each message, unless you want that message to continue running into the next one; however, the last cog message MUST be concluded with a return;
  2. Added some sender checking code in the activated message -- only the trigsurface should send the activated message. Without the if statement, surface 'floor' could also be activated to run the activated message.
  3. PlaySound() is not a cog verb.
  4. Zeq mentioned the vectors thing -- he's right. You can only have vectors in one of the following two forms: 'x y z', VectorSet(x, y, z); Note however that 'x y z' must have numbers in the apostrophes, not variables; if you must use variables, use VectorSet();
  5. Make your code flexible/reuseable; this is why I changed it so that the sector with the thrust is assigned in the level editor, as opposed to being a constant in the code; imagine if your cog got so complex that you had 50 instances in which you reference the sector, and sector 22 is changed somehow and becomes sector 25. It's certainly easier to make a single change in your level editor than to change all the 22's to 25's (without accidentally changing a wrong 22). In addition, you will be able to recycle your code and use it in another cog in which you need the same effect found in this one.
    [/list=1]
    Hopefully that all (remotely) made sense :o :)
May the mass times acceleration be with you.
2005-01-16, 12:32 PM #4
Thanks for the help guys, as I said, I'm just new at this:)
I've got a website. It's at Geocities because I'm too cheap to get my own site.

↑ Up to the top!