(solved) Why won't QueueMove work?

Started by Clean0nion, December 03, 2013, 02:17:52 PM

Previous topic - Next topic

Clean0nion

I have here two scripts.
The first is net_strafer_fly.crpl. It moves the strafer from point to point, decides what points to go to, and so on.
The second is net_strafer_pad.crpl. All it does is set up the other script.
Both of those links go to the respective scripts at pastebin.com.

The QueueMove at line 121 of net_strafer_fly.crpl doesn't work. It just doesn't do anything, and stops the script due to the location-based foolproofs I've added.

If anyone could diagnose this, that would be just lovely. Thank you.

eduran

#1
Edit: Forget what I said in the first paragraph.

SetScriptVar only works on input variables, i.e. you need to declare the variables by using $<varname>:<default_value> at the start of net_strafer_fly.crpl. Currently your script does not receive any variables from net_strafer_pad.crpl, which means you never assign a value to 'speed'. Therefore when you try to read 'speed' during QueueMove it defaults to 0.


Two other notes regarding your use of the trace log:

1) If you put ShowTraceLog/ClearTraceLog in a once-block you can monitor how variables change over time. Extremely useful in conjunction with single time steps to see what your script does on every frame. If you clear the log each frame you can only see variable values of the current frame.

2) Trace2/3/4/5 allow tracing multiple items on the stack at once. You could replace
"x1: " <-x1 concat Trace
with
"x1: " <-x1 Trace2Does not change the output, but it's faster to type, especially when using a lot of traces.

3) When trying to debug a problem like yours it can be very useful to put a trace command right next to the broken command. If the trace executes you at least know that you are reaching that part of the code and you can concentrate on checking the input for errors. If it does not execute you can focus on figuring out where the script gets stuck.

Clean0nion

#2
Quote from: eduran on December 03, 2013, 02:56:19 PM
SetScriptVar only works on input variables, i.e. you need to declare the variables by using $<varname>:<default_value> at the start of net_strafer_fly.crpl. Currently your script does not receive any variables from net_strafer_pad.crpl, which means you never assign a value to 'speed'. Therefore when you try to read 'speed' during QueueMove it defaults to 0.

Speed has already been tried and tested via the use of trace.
Trying again, setting speed to a constant.

UPDATE: Still doesn't work.

eduran

Apparently I am dead wrong in my analysis. At least I've learned something  ;D I'll report back when I've come up with a better idea of what is going wrong.

Grayzzur

Found it. You reversed X and Y. You're trying to queue a move to a location off the map, so it doesn't move.

You should be getting target coordinates this way, because the Y value will be the top item on the stack:
RandUnitCoords ->y1 ->x1
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

eduran

You are also putting a bunch of unused numbers onto the stack with GetImageColor on line 117. Not sure if that will cause a problem. Is there a maximum stack size?

J

Quote from: eduran on December 03, 2013, 03:25:26 PM
You are also putting a bunch of unused numbers onto the stack with GetImageColor on line 117. Not sure if that will cause a problem. Is there a maximum stack size?
There is a max stack size, if that is reached the oldest values will be removed. However if memory serves correctly the stack gets cleared everytime the scripts starts again from top (so the stack will be cleared after every frame if no Delay commands are used)

Grayzzur

Quote from: eduran on December 03, 2013, 02:56:19 PM
Does not change the output, but it's faster to type, especially when using a lot of traces.
Nice tip. I've never actually played with Trace2 and up, just assumed they'd put things on multiple lines.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

Clean0nion

Quote from: Grayzzur on December 03, 2013, 03:20:28 PM
Found it. You reversed X and Y. You're trying to queue a move to a location off the map, so it doesn't move.

You should be getting target coordinates this way, because the Y value will be the top item on the stack:
RandUnitCoords ->y1 ->x1
Thank you Grayzzur for your help both now and earlier! That does seem to be the issue.
Thank you all, as well.