PDA

View Full Version : First cogging attempt


COTF_Dude
08-01-2004, 04:46 PM
I wrote a cog and it works somewhat. Its supposed to move a thing to frame one, sleep, then move back to frame 0 and sleep and so on and so forth, but, it only moves to frame one and then Stays there. Here's the Cog
# Written By Dude
#
#Custom Shuttle Script
#
#
#================================================= ======

symbols

message startup
message timer

thing shuttle0

float movespeed=5.0
float sleeptime=6.0
float lightvalue=0.5

end
#================================================= ======

code

startup:

SetTimer(sleeptime);

MoveToFrame(shuttle0, 1, movespeed);

SetTimer(sleeptime);

MoveToFrame(shuttle0, 1, movespeed);

SetTimer(sleeptime);

return;

end


Please let me know what you do to it and why if you can. Im tryin to learn to cog. http://forums.massassi.net/html/smile.gif

------------------
Total Toothpickings; 7

a_person
08-01-2004, 09:22 PM
# Written By Dude
#
#Modified by a_person. Reason, Wasnt moving back through the frames.
#
#Custom Shuttle Script
#
#
#================================================= ======
symbols

message startup

thing shuttle0
flex movespeed=5.0
flex sleeptime=6.0

end
#================================================= ======
code
startup:

while(1) {
MoveToFrame(shuttle0, 1, movespeed);
waitforstop(shuttle0);
sleep(sleeptime);
MoveToFrame(shuttle0, 0, movespeed);
waitforstop(shuttle0);
sleep(sleeptime);
}

SetTimer(sleeptime);
return;
end


This should work for you. Firstly I got rid of all that timer stuff and made the sleep times sleep(). Then I added while(1) to make the cog continuously loop. Then the next movetoframe() frame value has to be 0.

I hope this helps.

Also I should add unless you add more frames the ship will fly backwards

/a_person

------------------
~Nightfire Mod (http://www.nightfire.uni.cc)~

[This message has been edited by a_person (edited August 01, 2004).]

lucky_jackpot
08-02-2004, 03:04 AM
That's not a bad effort for a first time COTF_Dude http://forums.massassi.net/html/smile.gif - just a couple tidbits of advice that I hope are helpful in your endeavours:

1) When you write "SetTimer(sleeptime)", what you are saying is to call the "timer" message - something that whilst you have acknowledged you are going to use in your cog symbols section, you haven't ended up implementing in your code section. Parsec would pick up this for you (see point 4).

2) Whilst timers are extremely useful (especially once you start dealing with multiple timers...), I think "Sleep()" would be better, as a_person suggests http://forums.massassi.net/html/smile.gif. Although not a huge fan of "Sleep()" myself, I readily confess that it has it's uses, certainly with regard to SP cutscenes, but anything to do with MP, then timers would be advisable but not obligatory (thought I'd throw in a disclaimer before some people pick me up on this...)

3) On an aesthetic note, don't overdo your code indentation http://forums.massassi.net/html/wink.gif take it from someone who knows, indenting your code for readability is one thing, but indenting every line could be construed as maybe a tad bit excessive... http://forums.massassi.net/html/tongue.gif

4) My other main counsel would be to download the DataMaster (a.k.a the COG BIBLE - always good for a bit of bedtime reading http://forums.massassi.net/html/wink.gif) and Parsec (for debugging your cog scripts - a totally invaluable resource http://forums.massassi.net/html/biggrin.gif). Both of these can be found at SaberMaster's site: http://geocities.com/sabersdomain/ - download these and you will be sorted for life (as far as JK cogging is concerned) http://forums.massassi.net/html/biggrin.gif

Well I hope these "sage words" are of some help - keep up the good work http://forums.massassi.net/html/biggrin.gif

-Jackpot

------------------
"lucky_jackpot is the smily god..." - gothicX
"jackpot is an evil evil man... so evil, in fact, that he's awesome." - Seb

"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)

COTF_Dude
08-02-2004, 12:39 PM
Thanks for all the help. I'll be sure to d/l that stuff. I was using the 00_Door.cog for a reference on how to do it. http://forums.massassi.net/html/smile.gif

------------------
Total Toothpickings; 7

a_person
08-02-2004, 09:28 PM
Haha I remember my attempt to use 00_door.cog when i was starting out.

------------------
~Nightfire Mod (http://www.nightfire.uni.cc)~

F-Body
08-03-2004, 07:24 PM
Also, don't use "float". Use "flex" instead, even though it is essentially equal. float is older and I guess has issues with certain things (not sure what/why just do it http://forums.massassi.net/html/wink.gif )

------------------
nil nip nada zip zero naught lip zil

LKOH_SniperWolf
08-03-2004, 11:32 PM
As far as I'm aware there's no special problems with floats. The only problem I know of applies to both floats and flexs, and that is floating point precision error, which simply has to do with the way information is stored. (Binary sucks for storing decimals, so after a certain point there is error. Other than that, I believe flex is just something common in cogs, though flex and float work the same as far as I'm aware.)

------------------
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come