Haskell gloss loading .bmp

1.8k views Asked by At
-- | Main function
main :: IO ()
main = do 
          wall <- loadBMP "wall.bmp" -- loads wall image
          play initialState drawState reactEvent reactTime


-- | Function that creates the game
play :: State -> (State -> Picture) -> (Event -> State -> State) -> (Float -> State -> State) -> IO ()
play initialState drawState reactEvent reactTime = play
            (InWindow "Game" (900, 900) (0, 0))      -- Window ize
            (greyN 0.5)                              -- background coloer
            1                                        -- refresh rate
            initialState                             -- initial state
            drawState                                -- draws game state
            reactEvent                               -- teacts to evente
            reactTime                                -- reacts to time

-- | One game represenction
type State = (Map,Picture)

-- | Initial game state
initialState :: State
initialState = ((map 13 0),wall)

The function map creates my map. My game is already running fine, but I need to replace the representations i used (circles from gloss) with some BMP images, but i can't load even one cause when i try to load this wall it appears an error in the last line I shared here: not in scope 'wall'

Can someone see why this is happening?

1

There are 1 answers

1
Chai T. Rex On

When you define main, the variables you create there aren't accessible outside of the definition of main. initialState is outside the definition of main.

You need to pass wall into initialState by changing main and initialState like this:

main :: IO ()
main = do 
          wall <- loadBMP "wall.bmp" -- loads wall image
          play (initialState wall) drawState reactEvent reactTime

 

initialState :: Picture -> State
initialState wall = ((map 13 0),wall)