Need help with grid-based travel

Couldn’t find something that uses the Nestled? Crossed? Variables.

*comment Records room data.
*create cell_x1_y1 "entrance"
*create cell_x1_y2 ""
*create cell_x2_y1 ""
*create cell_x2_y2 "exit"

*comments Records player position.
*create player_x_position 1
*create player_y_position 1

I want to try and do something the following below, so that if player_x_position or player_y_position changes, it will retrieve different room data.

*comment The desired output is "entrance," then "exit." 
*comment Instead there's a token error.
${cell_x${player_x_position}_y${player_y_position}}
*set player_x_position +1
*set player_y_position +1
${cell_x${player_x_position}_y${player_y_position}}

If there’s another post facing similar issues, a different way to approach this, or otherwise some help with tackling it down, any help would be appreciated!

I once did that, years ago. The characters explored a island in a war game. I also remember trying to implement a AI of sorts that managed the roaming of the other characters in the island.

Hmm
Try this:

*comment Records room data.
*create cellxy_11 "entrance"
*create cellxy_12 ""
*create cellxy_21 ""
*create cellxy_22 "exit"

*comments Records player position.
*create player_x_position 1
*create player_y_position 1

Then

*comment The desired output is "entrance," then "exit." 
*comment Instead there's a token error.
*temp coordinates  (player_x_position&player_y_position)

${cellxy[coordinates]}

*set player_x_position +1
*set player_y_position +1
*set coordinates (player_x_position & player_y_position)


${cellxy[coordinates]}

Hmm. Not sure if I write it right.

I believe the interpreter will ignore the “_” in the variable name and treat the “[” and “]” as if you written the var name yourself. ‘Reading’ the number from the values if the variables you wrote inside the “[ ]”.

I am pretty sure you can also do that putting the game of your scenes/labels in a variable and put the variable in a ‘*goto’ or ‘*gosub’ command.

From my understanding, when CS sees blah[7], it translates it as blah_7.

So having arrays of the form cell_x[i]_y[j] won’t work, because CS translates it as cell_x_i_y_j.

AFAIK there are two ways around this: [1] change your variables so the indices are perceeded by an underscore (e.g., cell_i_j) or [2] use concatention.


Concatention Example:

*create cell_x1_y1 "entrance"
*create cell_x1_y2 ""
*create cell_x2_y1 ""
*create cell_x2_y2 "exit"

*create player_x_position 1
*create player_y_position 1

*create xy_position ""

*gosub set_xy_position
${{xy_position}}

*set player_x_position + 1
*set player_y_position + 1
*gosub set_xy_position
${{xy_position}}

*finish

*label set_xy_position
*set xy_position ("cell_x"&player_x_position)&("_y"&player_y_position)
*return

Array Example:

*create cell_1_1 "entrance"
*create cell_2_2 "exit"

*create x 1
*create y 1

${cell[x][y]}

*set x + 1
*set y + 1

${cell[x][y]}

*finish
2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.