Game Development Community

This makes no sense. Echo not returning.

by rennie moffat · in Torque Game Builder · 06/02/2010 (8:56 am) · 8 replies

for some reason, beyond me my echos here are not returning anything. Very frustrating. Even more so is that, this code, the reason I am using it, was working perfectly... now, not so much. Errr. It just makes no sense!!!


echo("thisBehavior::onUpdate");
echo(" %atPos " @ %atPos);
echo(" %atPosX " @ %atPosX);
echo(" %atPosY " @ %atPosY);

%atPos = %this.owner.getPosition();
%atPosX = getWord(%atPos, 0);
%atPosY = getWord(%atPos, 1);

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
06/02/2010 (9:20 am)
If you want people to help, try posting the actual code that you're using. If you are indeed using the code you posted above then no wonder it outputs nothing, you're setting the local variables after you echo them.

#2
06/02/2010 (9:52 am)
oh shoot. I thought about that. But then just didn't think it mattered, regarding echo placemnt.

ok so it is working, the echo are returning, however the problem remains.


The reason I am using these variables it to flip, or switch my enemy layer. If the player is in any one of the 4 quadrants from my enemy's center axis the enemy switches accordingly so that it appears, behind or in front. It is a perspective thing. Anyhow, I have gotten it to work, several times in all enemy behaviors, but it has, in this one given my problems and I am unsure why.


%atPos = %this.owner.getPosition();
	%atPosX = getWord(%atPos, 0);
	%atPosY = getWord(%atPos, 1);
	echo("antiTemple2A::onUpdate");
	echo("  %atPos " @ %atPos);
	echo("  %atPosX " @ %atPosX);
	echo("  %atPosY " @ %atPosY);
///temple is the player. 
//at is the enemy
	echo("  $templePosition " @ $templePosition);
	
    if(%atPosX <= $templePosX && %atPosY > $templePosY)
	{
		%this.owner.setLayer(5);
	}
	if(%atPosX <= $templePosX && %atPosY < $templePosY)
	{
		%this.owner.setLayer(3);
	}
	if(%atPosX >= $templePosX && %atPosY < $templePosY)
	{
		%this.owner.setLayer(3);
	}
	if(%atPosX >= $templePosX && %atPosY > $templePosY)
	{
		%this.owner.setLayer(5);
	}


idk, as I say I have gotten it to work, and I think it should, but for some reason it is not. Any thoughts?
#3
06/02/2010 (9:57 am)
ps this is in the enemies onUpdate().
#4
06/02/2010 (10:16 am)
to tell you the truth it really is not a major thing, but if you see something fishy please let me know.


#5
06/02/2010 (10:34 am)
Your code is getting complex at this point. We need to see the entire behavior, or at least more context before we can offer more help.

Like, when is the above code being called? [EDIT]in onUpdate. When are all those global variables being updated?

What does the other behavior (the one that works) look like?


I've only been watching these forums for the last few months, and you seem to be having a lot of problems missing the little things. Might I suggest picking up a license for Torision? It'll help you keep all of your globals, functions, arguments etc. in check and help you with debugging. Honestly, a lot of your problems would be solved by going back over your code with a careful eye, so having Torision to help you with that would save you the trouble of posting here to have other people look at your scripts.

From what I can tell, you need to trace your code sequentially and watch when the variables are being set when things go wrong. Get a piece of paper or open notepad and go down your code line by line and write down the current values for each of the important variables in that function. Watch where they change and if the values are coming up the way you want (if they come out right on paper, then you probably have a math error). If you don't know what a variable's value is, go trace where it came from.

The hard part of debugging your code is not ASSUMING that things work the way you want. You ASSUMED the %atPos variable would contain the data you wanted, but they hadn't been initialized.

When things go wrong, pretend you know nothing and go back and be really explicit about what's happening with the script. Forget what the variables mean and what they're named and look at it with fresh eyes.



And another thing... why are you using a bunch of global variables for values that are already associated with the player object?

Why can't your player be $temple, and why can't $templePosition be $temple.getPosition() ?

You're duplicating data manually - any time you duplicate data manually, you run the risk of screwing it up yourself. If you accidentally misspell $templePoSSSition, for example, the engine will create a brand new variable and allocate MORE memory, causing you more headaches because that variable will have some weird garbage value, rather than giving you a syntax error.
#6
06/02/2010 (10:36 am)
Quote:But then just didn't think it mattered, regarding echo placemnt.

Seriously? Like it just automatically knows what to run in what order or just picks a random one. ;)

Tell me you were kidding! :)
#7
06/02/2010 (12:58 pm)
I don't think he was (shudder)
#8
06/02/2010 (1:28 pm)
@Melv. no. I wasn't. I remember asking about placement inside a function and came to a conclusion, I guess wrong, that the computer goes into the function, gathers all information, then makes decisions. But I guess not, it starts piling the info as soon as it sees it!


Yes yes,
newb (well a year of experience) in dah houssse.



@Daniel
I would like to use torsion, but I used the demo and needed a crossover software, mac to PC and the crossover just seemed to muck up my Mac a bit. Any thoughts on Mac Torsion use? I know I researched it a while ago via the forums. There seems to be a lot of disappointed Mac users.

Quote:
Why can't your player be $temple, and why can't $templePosition be $temple.getPosition() ?

not sure, I had just made it as such. Previously I had actually been calling it with in that function like so..
///inside the same enemy onUpdate
%this.templePos = %this.temple.getPosition();
%templePosX = getWord(%this.templePos, 0);
%templePosY = getWord(%this.templePos, 1);


Anyhow, a real bugger since as I say I have gotten it to work. And also Daniel, The behavior I have is 0ver 700 lines long, I don't think you want to go thru that. I should be able to solve it. The main code in question, of any significance is the code already posted. But thanks. If you really want to see it I can post it but I don't think it is necessary.