Playdateapi* null in C (custom update)

haven't gotten anything to run yet, working on first prototype for game

here is the code

#include <stdio.h>
#include <stdlib.h>
#include "pd_api.h"

static int update(void* userdata);
static LCDFont* Font = NULL;
PlaydateAPI* playdate = NULL;

int update(void* userdata);
void drawMenu();
void drawGame();

int eventHandler(PlaydateAPI* playdate, PDSystemEvent event, uint32_t arg) {
switch (event) {
case kEventInit:
//C init code
Font = playdate->graphics->loadFont("font.pft", NULL);
playdate->system->setUpdateCallback(update, playdate);
break;
case kEventInitLua:
// lua = bad
break;
case kEventKeyPressed:
//scoobydoo shit right here
break;
case kEventKeyReleased:
//
break;
case kEventLock:
//lock event
break;
case kEventUnlock:
//unlock event
break;
case kEventPause:
//pause event
break;
case kEventResume:
//resume event
break;
case kEventTerminate:
//arnold event
break;
case kEventLowPower:
//sleep event
break;
default: // do i need this?

    break;
}


return 0; 

}

int update(void* userdata) {

PlaydateAPI* playdate = userdata;

switch (currentGameState) {
case MENU:
    drawMenu();
    break;
case GAME:
    drawGame();
    //woweee
    break;
}

return 1;

}

void drawMenu() {
playdate->graphics->clear(kColorWhite);

...

so the issue im having is that when i go to clear the screen the playdateAPI* is still set to NULL?

the update function should have already set the pointer to "userdata" from the hardware before clear gets called?

this will be my first project in c in many years, thank you for your understanding.

You created a global variable named playdate at the start of the file:

#include <stdio.h>
#include <stdlib.h>
#include "pd_api.h"

static int update(void* userdata);
static LCDFont* Font = NULL;
PlaydateAPI* playdate = NULL;

int update(void* userdata);

However in update, you are assigning the API to a new local variable instead of the global one:

int update(void* userdata) {

PlaydateAPI* playdate = userdata;

So when you try to access the global variable in your draw functions, its value is still NULL.

My recommandation would be to assign the global playdate variable in the eventHandler and to use userdata to store the game state:

int eventHandler(PlaydateAPI * _Nonnull api, PDSystemEvent event, uint32_t arg) {
    switch (event) {
        case kEventInit:
            playdate = api;