Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Strive for Power

Fantasy Slave Management/RPG Erotic Game · By Strive4Power

How to check if file exist?

A topic by harryholliday created Sep 21, 2019 Views: 457 Replies: 3
Viewing posts 1 to 4
(3 edits)

Hi Striver, I know this is a newbie question. Anyway, how to check if file exist for loadimage? I thought using null would work. 

I'm trying to give naked picture for sexscene. What I want is, if image exist in naked folder, load them (success); if not, load the image in bodies folder (blank, it still trying to load the image from naked folder).

Here's my modified script in newsexsystem.gd

func showbody(i): if globals.loadimage(i.person.imagefull.replace('bodies', 'naked')) != null: $Panel/bodyimage.visible = true $Panel/bodyimage.texture = globals.loadimage(i.person.imagefull.replace('bodies', 'naked')) print(i.person.imagefull.replace('bodies', 'naked')) elif globals.loadimage(i.person.imagefull) != null: $Panel/bodyimage.visible = true $Panel/bodyimage.texture = globals.loadimage(i.person.imagefull) print(i.person.imagefull) elif nakedspritesdict.has(i.person.unique): ...

Nevermind. Just realize it's a gdscript question, not a strive one.

(1 edit)

Don't try to load a file and then figure out whether or not you were successful.  Check to see whether or not the file exists.  Make use of the 'File' class and the function 'file_exists'. (Although I haven't looked at the function you are calling.  Maybe that already tests for existence).

Thx, it works. I copied a line from loadimage function itself. 

func showbody(i):
    if globals.loadimage(i.person.imagefull) != null:
        $Panel/bodyimage.visible = true
        if File.new().file_exists(i.person.imagefull.replace('bodies', 'naked')):
            $Panel/bodyimage.texture = globals.loadimage(i.person.imagefull.replace('bodies', 'naked'))
        else:
            $Panel/bodyimage.texture = globals.loadimage(i.person.imagefull)
    elif nakedspritesdict.has(i.person.unique):
        ...