Substring or string manipulation

  1. Describe your reason for requesting this feature. What problems are you running into?

To save on massive if statements it would be great to be able to do left({string variable},5). I have sprites for left and right and need to do the same logic on the sprite. so instead of

if name==hatch-left" then
else if name=="hatch-right" then
else if name=="hatch-up" then
else if name=="hatch-down" then
else if name=="hatch-up-left" then
else if name=="hatch-up-right" then

etc vs

if left(name,5)=="hatch" then

or allow for boolean and compound checks in if statements, OR and AND would save loads of code.

  1. How would this request improve your experience with using Pulp?

Less code written.

  1. Include any other details you have relating to this request.
3 Likes

I believe that this functionality will be available once everyone has access to the SDK (which supports LUA and C), so I'm not sure if this will be a priority for Pulp.

I'm facing the same problem -- huge conditionals just to test if a tile is a member of a set that are clearly labelled.

Being able to get the first n characters of a string would let Pulp scripters do a lot more with this engine, using not just a lot less code, but a lot fewer comparisons.

Suggested design:

tilename = name last_x, last_y
trim tilename, 5 // tilename is now only the first four letters of the tile's name
if tilename == "water" then
  player_pose = "swim"
end
3 Likes

It would be great if this functionality could still be implemented. I have 5 different grass patterns and I'd like to check if the player is on "Grass01", "Grass02", "Grass03", "Grass04" or "Grass05" a little more elegantly. My workaround solution was to try and create a single "Grass" tile with 5 different frames of animation (0 fps) and randomize them on startup, but that would require me to make them into sprites (to use emit) which I don't want to do for collision reasons. Thanks!