Squashing Bugs and building robust systems.


I've mostly been fixing up bug lately and it's been REALLY fun!

image

Two main themes
1. Splitting up the state of the player so I can turn player sprite elements off and on at different times.

Update bugs

2. Implementing my own metadata system.
Having a sprite that is two tiles means you run into a lot of edge cases where things look wrong. When you want to hide the player so it looks like they are behind a wall.

And then i'm wanting to place down a lamp in the world. But I don't want to place it if... ~the light level is 0 (Then the player can loose it) ~if the location you're placing it is solid ~if the location you're placing the lamp is "behind" something (As it would replace the tile)

The only meta data tiles have is solid or not. You can't define a tile as above.

I was planning to simply list many if statements for each "above" tile but @orkn had a better idea. So all credit to him on this one.

"So if the solid function didn't exist, and we wanted some way of knowing if a tile is "solid"
or not, and we wanted to check if a tile is solid or not in multiple places around our project, 
we might decide to make our own version of the solid function. In the game script we add:
    on isTileSolid do
      if tile=="white" then
        tileIsSolid = 0
      elseif tile=="black" then
        tileIsSolid = 1
      end
    end
and we can keep adding elseifs for every tile in our game. (As a potential optimisation we realise
we could start the event with tileIsSolid = 0 and then only add ifs for those tiles that are solid, 
but maybe we appreciate the explicit list of all tiles as it makes changing the metadata easier, idk!)
Then wherever in our code we want to check if a tile is solid, we do this:
    tile = name x,y
    tell event.game to
      call "isTileSolid"
    end
    myTileIsSolid = tileIsSolid
and that is functionally equivalent to the actually built-in
    myTileIsSolid = solid x,y
The isTileSolid event is effectively a function with an input tile and an output tileIsSolid,
it's just Pulpscript doesn't support event arguments and return values so we just have to be careful
juggling global variables. The solid function does exist, so this isn't necessary, but if we want to
add new kinds of "metadata" to tiles, like their "aboveness" in this case, then you could take this
approach."

I took that and made the following.

In game I have

on isTileAbove do
  
    tileIsAbove = "false"
    if aboveTarget=="roof top" then
        tileIsAbove = "true"
    elseif tile=="other" then
        // tileIsAbove = "true"
    end
end

And in my on cancel event which I use tileIsAbove for checking if the player can place the lamp

Above

Place lamp code

on cancel do
    
    if lampHeld=="true" then // holding the lamp | There's zero lamps on the screen
        lampTargetX = event.px
        lampTargetY = event.py
        
        if playerLastMove=="L" then
            lampTargetX--
        elseif playerLastMove=="R" then
            lampTargetX++
        elseif playerLastMove=="U" then
            lampTargetY--
        elseif playerLastMove=="D" then
            lampTargetY++
        end
        
        lampTarget = name lampTargetX,lampTargetY
        lampTargetSolid = solid lampTargetX,lampTargetY
        aboveTarget = lampTarget
        tell event.game to
            call "isTileAbove"
        end
        
        if lightRadius>0 then
            if lampTargetSolid==0 then
                if tileIsAbove=="false" then
                    tell lampTargetX,lampTargetY to
                        swap "Lamp"
                        lampHeld = "false" // not holding the lamp
                        lampRoom = event.room
                        
                        if illumination=="dark" then
                            // re-illuminate the room so that the radius now centers around the lamp instead of the player
                            emit "darken_tile"
                            tell event.game to
                                call "darken_room"
                                call "illuminate_tiles"
                            end
                        end
                        
                    end
                elseif tileIsAbove=="true" then
                  sound "prohibited"
                    say "Can't Place lamp behind things" at 1,10,21,3
                end
            elseif lampTargetSolid==1 then
                sound "prohibited"
            end
        elseif lightRadius==0 then
            sound "prohibited"
            say "I don't want to lose this lamp in the darkness" at 1,10,21,3
        end
    end
end

Get Comet

Leave a comment

Log in with itch.io to leave a comment.