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 → Sendmessages can't change variables
Sendmessages can't change variables
2001-09-03, 11:58 AM #1
I'm sending several messages to a template cog. But none of the messages can use any of the variables of the template cog. For example:

user0:

Print("Message Received");
var=1;
Printint(var);

Return;

The Print runs and printint prints 1, but var will still be 0 in the cog's other messages. What am I doing wrong?


------------------
Truth is in the eye of the beholder

[This message has been edited by SaberMaster (edited September 03, 2001).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-09-03, 9:01 PM #2
I don't know if it works but you probably have to declare "var" "global" (don't know if it is the right keyword) and not "local" in the calling cog.

It is better to use parameters.

[This message has been edited by Nemios (edited September 04, 2001).]
"May the SourceCode be with you..."
Nemios, MOD developer.
2001-09-03, 10:37 PM #3
Can you post the whole cog so I may be able to find out what's wrong.

------------------
http://millennium.massassi.net/ - Millennium
2001-09-04, 10:00 AM #4
Here's the cog:

Code:
symbols

template	smoke=+smoke
thing		player
thing		proj
int		var
int		counter

message	created
message	timer
message	removed
message	manualremove
message user0
message user1
message user2

end
#=============================================================================#
code
#============================================#
created:
   player=GetSourceRef();
   proj=GetSenderRef();
   SetThingVel(proj, VectorScale(GetThingLVec(proj), .5));
   var=0;
   counter=0;
   SetInv(player, 116, 1);
   SetTimerEx(0.01, 1, 0, 0);

Return;
#============================================#
timer:

Printint(var); #Always zero
Creatething(smoke, proj);
counter=counter+1;
if(counter >= 300)
{
   call manualremove;
   Return;
}

SetTimerEx(0.01, 1, 0, 0);

Return;
#============================================#
manualremove:
   Killtimerex(1);
   SendTrigger(-1, 22, proj, 0, 0, 0);
   Destroything(proj);

Return;
#============================================#
removed:
   Killtimerex(1);
   SetInv(player, 116, 0);

Return;
#============================================#
user0:
   call manualremove;
   Print("user0");
Return;
#============================================#
user1:
   var=1;
   Printint(var);
   Print("user1");
Return;
#============================================#
user2:
   var=0;
   Print("user2");
Return;
#============================================#
end


The whole cog would have been to big, so I shortened it down to this and then tested it to make sure the problem was still there.

When user0 is run, it calls manualremove. Then manualremove crashes because it cannot find proj. But when counter gets to 100 and the timer calls manualremove, it works.

User1 Prints "1" and then "user1", so it seems to set var to 1. But, timer will still print var as 0. User2 has the same problem. I tested this cog with and without the symbols being defined as local. What do I need to change here?

------------------
Truth is in the eye of the beholder
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-09-04, 1:34 PM #5
I too think that the variable is declared as global as no "local" is placed. If you have no need to set those variables through JED, then you can all call them as local.

And a few more things in that cog too.

1. You don't need to declare your own defined message in the symbols section.

2. You can't get "player" as "GetSourceRef()" in the created message, use "GetLocalPlayerThing()" instead.

3. Matter of possible or not, but if your timer is set as "0.01" in the timer message, you will probably can't kill the timer within the "0.01" wait by the "removed" and "manualremove" message. And if you want to start the "timer" message after "0.01" seconds, then you can rather do "call timer;" as well.

Good luck [http://forums.massassi.net/html/smile.gif]

------------------
http://millennium.massassi.net/ - Millennium
2001-09-05, 7:15 AM #6
1. If I take out the user messages from the symbols section, the messages won't be received by the cog.

2. What will GetSourceRef() return in the created message? I'm not using GetLocalPlayerThing() because I think it's causing multiplayer problems. IE, if the cog is run locally on all computers, then everybody will be their own local player.

3. The timer is killed by the removed messages. But if it's a question of computer speed, my comp is 900 Mhz; so that might be it. I replaced the settimerex() in the timer message with call timer; but it didn't work. Timer just didn't run after the first time.

What should I do to fix the user message problem? [http://forums.massassi.net/html/confused.gif]

------------------
Truth is in the eye of the beholder

[This message has been edited by SaberMaster (edited September 05, 2001).]
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2001-09-05, 1:33 PM #7
1. I mean "manualremove" not "userX".

2. GetSourceRef() probably returns nothing.
If you need to get a particular player, think of the relativity between the projectile and the player, is it something like GetThingParent(proj)? Then I suggest you go with that. You can't just get a player instantly out of nowhere except for GetLocalPlayerThing().

3. Hmm, call timer may not work. SendMessageEx(GetSelfCog(), timer, blah...); neither worked for me in the past. Using a small amount of timer may do better, but if you only use it for 0.01 seconds of wait, there is no need for a timer, just make it as a manual message and call that.

In whatever comp I guess you really can't KillTimerEx a 0.01 timer...unless they are both in the same message of a cog...

------------------
http://millennium.massassi.net/ - Millennium

↑ Up to the top!