Jump to content

ERROR: cannot convert %x_idx% or %%x_idx%% to an i


Victor

Recommended Posts

When I run the tp2 file below, as shown, I get the error:

 

ERROR: cannot convert %x_idx% or %%x_idx%% to an integer

 

However, when I comment out the second READ_BYTE I get the following values:

 

x_idx is 9

area_num is 25

area_to is 11

area_off is 200

areafile is AR0020

loops is 12

link_idx_1 is 81

flags is 0

 

So anyone know what I'm doing wrong? (CamDawg, I'm sure you will recognize some of the artfacts left from your code. You must have solved this before, any comments?)

 

BEGIN ~Ar1300 patch~

// need to patch the world so party can exit area

 

COPY_EXISTING ~worldmap.wmp~ ~override~

READ_LONG 0x30 "area_num"

READ_LONG 0x34 "area_off"

READ_LONG 0x38 "link_off"

READ_LONG 0x3c "link_num"

WRITE_LONG 0x3c ("%link_num%" + 4)

 

SET "loops" = 0

SET "x_idx" = 0

SET "area_to" = 0

SET "link_idx_nsrt" = 999999

 

WHILE ("%area_num%" > "%loops%")

AND (("%area_to%" < 1) OR ("%x_idx%" < 1)) BEGIN

 

READ_ASCII ("%area_off%" + ("%loops%" * 0xF0)) "areafile"

PATCH_IF ("AR0020" STRING_COMPARE_CASE "%areafile%" = 0) BEGIN // Find index for City Gates

SET "area_to" = "%loops%"

END

 

PATCH_IF ("AR1300" STRING_COMPARE_CASE "%areafile%" = 0) BEGIN // Find keep index

READ_LONG ("%area_off%" + 0x50 + ("%loops%" * 0xF0)) "link_idx_1"

SET "link_idx_nsrt" = "%link_idx_1%"

SET "x_idx" = "%loops%"

END

 

SET "loops" = ("%loops%" + 1)

END

 

READ_BYTE ( "%area_off%" + 0x30 + (9 * 0xF0)) "flags"

READ_BYTE ( "%area_off%" + 0x30 + ("%x_idx%" * 0xF0)) "flags"

 

PRINT ~x_idx is %x_idx%~

PRINT ~area_num is %area_num%~

PRINT ~area_to is %area_to%~

PRINT ~area_off is %area_off%~

PRINT ~areafile is %areafile%~

PRINT ~loops is %loops%~

PRINT ~link_idx_1 is %link_idx_1%~

PRINT ~flags is %flags%~

Link to comment

The best bet is usually initializating the variable in a bogus READ, EG:

 

...

SET "loops" = 0

READ_BYTE 0 "x_idx"

SET "x_idx" = 0

SET "area_to" = 0

...

 

don't ask me what's the problem or why it doesn't work, all I know (and this is enough to me) is that this skips the problem :p

Link to comment

Yes it does, thanks. (Mine is not to reason why, ...) I've spent an unbelievable amount of time on different variations on this.

 

Hot Damn it works!!!

 

 

The best bet is usually initializating the variable in a bogus READ, EG:

 

...

SET "loops" = 0

READ_BYTE 0 "x_idx"

SET "x_idx" = 0

SET "area_to" = 0

...

 

don't ask me what's the problem or why it doesn't work, all I know (and this is enough to me) is that this skips the problem :p

Link to comment

All the READ_ actions are executed first to support IF_EVAL. If you use a variable that is uninitialized by a READ_ (i.e., you use SET, which isn't part of process_patch1) in a READ_ action, it won't be valid for that first pass.

 

If you want to be really clever, and cut down the amount of work WeiDU needs to do, you can always utilize the ELSE paramter for READ_ actions: READ_BYTE SOURCE_SIZE + 1 x_idx ELSE 0 -- as long as you pass in a location that will always be invalid (either < 0 or > SOURCE_SIZE), the variable will always be set to the ELSE value. Then, you have something that should work on the first IF_EVAL pass, and will work when the TP2 is executed normally (and you won't require both the READ_ and the SET).

Link to comment
All the READ_ actions are executed first to support IF_EVAL. If you use a variable that is uninitialized by a READ_ (i.e., you use SET, which isn't part of process_patch1) in a READ_ action, it won't be valid for that first pass.

 

If you want to be really clever, and cut down the amount of work WeiDU needs to do, you can always utilize the ELSE paramter for READ_ actions: READ_BYTE SOURCE_SIZE + 1 x_idx ELSE 0 -- as long as you pass in a location that will always be invalid (either < 0 or > SOURCE_SIZE), the variable will always be set to the ELSE value. Then, you have something that should work on the first IF_EVAL pass, and will work when the TP2 is executed normally (and you won't require both the READ_ and the SET).

Unless I understood wrongly, this applies only with IF_EVAL...

 

However, that tp2 truncon doesn't have IF_EVAL at all... Does that shitty "READ_ before everything else" rule apply to all tp2 or only to those with IF_EVAL?

Link to comment
Does that shitty "READ_ before everything else" rule apply to all tp2
Yes. You can go here for my latest "I hate IF_EVAL" post. If you can compile your own version of WeiDU, see Reply 2 there for a quick hack to disable the initial pass and kill off IF_EVAL.

Uh, I guess I'll have to edit my signature then :p

I should be able to recompile WeiDU, but I like to think that my mods work for everybody, and viceversa (I still remember the last time when I sent to Littiz a code using &&, || et similia in anticipation of the WeiDU release with them :p )

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...