The problem probably lies with your eventing, not with the script I think... Maybe post your event?
The only thing I can think of is that $game_map.priorities[@tile_ID] is not an integer, but that's a default script, so there shouldn't be a problem. I'm not sure. Post your event and I'll see if I can bypass that problem through eventing.