Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Nested expressions - Are they possible?

A topic by Stringsnapper created Sep 05, 2024 Views: 170 Replies: 1
Viewing posts 1 to 2
(1 edit)

Hi! I'm new to the Easy FPS Editor CE and I'm trying to figure out why my if-statements don't work as expected. I have a loop-script that is supposed to spawn enemies at random with a delay by ticking up a "spawnPoints" variable that is used to "purchase" enemies. Enemies will then only spawn if a "diceRoll" is higher than a specific value.

```

posX = RANDOM(0,64)
posY = RANDOM(0,64)
diceRoll = RANDOM(1, 1000)
willSpawn = 940
// Check if spawnPoints are enough for spawning an enemy
if $map.spawnPoints > $map.spawnCost {
    // Check the dice roll
    if $diceRoll > $willSpawn {
        entity spawnat "bat_angry" $posX $posY 0
        map.spawnedEnemies++
        map.spawnPoints=0
    } else {
        map.spawnPoints++
    }
} else {
    map.spawnPoints++
}
status "$map.spawnPoints"

``` 

Somehow the inner else-statement gets executed instead of the outer, even though I can see that the spawnPoints are lower than the spawnCost.

(+1)

I now believe that the issue is that the first else-statement gets executed regardless of which if-statement it is in. That means that nested if-statements are not possible in this way. I ended up solving it with a procedure instead. I should clarify that this is a loop script. 


procedure trySpawn
willSpawn = 90
diceRoll = RANDOM(1, 100)
map.spawnPoints=0
if $diceRoll > $willSpawn {
    posX = RANDOM(0,64)
    posY = RANDOM(0,64)
    entity spawnat "bat_angry" $posX $posY 0
    map.spawnedEnemies++
}
end
if $map.spawnPoints > $map.spawnCost {
    call trySpawn
} else {
    map.spawnPoints++
}
status "spawned Enemies: $map.spawnedEnemies"