How do I do the do function?

I'm currently trying to find a way to control the spawn rate of my Pokemon in my game, and I have been thinking up code to do that. Here's what I have so far:

game.spawn = false
game.count2 = 1
game.changedcount2 => {
  switch (game.count2) {
    case (1) {
      game.spawn = false
    }
    case (6) {
      game.count2 = 1
    }
  }
}

[filler text]
Each time the player enters a room, count2 goes up.

game.count2 = game.count2 + 1

I figured the simplest way to do this is with the do function. I'm not sure how it works though. I saw it a couple times, and I tried it once, but I never got it to work.


You are missing two } from the end of your code, but that is probably just missed when you copy-and-pasted it. And personally, I would do the work in the room enter script, i.e., move the content of the change script into the second script, though admittedly I am not sure if there is any great benefit.

The code looks okay, as long as something somewhere is going to react to game.spawn being true. I would guess that is the problem. Do you want a function call there?

game.count2 = 1
game.changedcount2 => {
  switch (game.count2) {
    case (1) {
      SpawnPokemon()
    }
    case (6) {
      game.count2 = 1
    }
  }
}

What are you going to use the do function for? I don't see how it would be useful to you.

do just runs a script attribute on an object. In this case, the script attribute you've got is named changedcount2, so it will be run automatically whenever count2 changes.

In this case, you seem to be making the code a lot harder than it needs to be. If you just want a monster to spawn every 6 turns, you could do something like:

game.count2 = 1
game.changedcount2 => {
  if (this.count2 >= 6) {
    this.count2 = 1
    // call the function that spawns an enemy here
  }
}

(I've kept the name count2 even though this is a really bad name for an attribute; it makes it harder for anyone trying to help you with bugs in your code, because it's not clear what the count is for)

OR, in your game's roomenter script:

game.spawncount = game.spawncount + 1
if (game.spawncount >= 6) {
  game.spawncount = 1
  // call the function that spawns an enemy here
}

If this doesn't work for some reason, maybe you could give a better idea of what you're trying to do.

In one of my games, the roomenter script contains a slightly more complex version:

spawnchance = null
maxspawnchance = 1
spawntype = null
foreach (room, ListParents (game.pov)) {
  if (spawnchance = null and HasInt (room, "spawnchance")) spawnchance = room.spawnchance
  if (maxspawnchance = 1 and HasInt (room, "maxspawnchance")) maxspawnchance = room.maxspawnchance
  if (spawntype = null and HasString (room, "spawntype")) spawntype = room.spawntype
}
if (not spawnchance = null) {
  this.spawncount = this.spawncount + 1
  if (this.spawncount >= GetRandomInt (maxspawnchance, spawnchance)) {
    this.spawncount = 0
    if (spawntype = null) spawntype = game.defaultspawntype
    spawn = PickOneString (Split (spawntype))
    SpawnEnemy (game.pov.parent, spawn)
  }
}

(in this version, rooms and regions can have an attribute spawnchance to control the frequency of monsters in that room, and spawntype which contains a string like "zombie;ghost;walrus" to specify what you might encounter there)


  1. Yes, I missed it in copy and pasting. It should be fixed.
  2. I am putting do an attribute's script; I want to do an attribute script, and I want to put it in the room's on enter script.

It's simple, then.

do (name of object, "name of script attribute")

Seems an odd way to structure your code, though.


Thanks.

How would you do it?

If I put something like Route 24 in every eoom, how could I make it so that every time the player entered the room, every counter (24, 25, 26, and so on...) went up?


Every counter? You mean every room has its own counter? So that every 6th time you enter that room, an encounter spawns?
I'd say just put a counter in the room and then increment it.

Or do you mean entering any of the rooms causes all the counters to go up? Because if you do that, the counters will always have the same value; so you might as well just have a single counter.


Every counter? You mean every room has its own counter? So that every 6th time you enter that room, an encounter spawns?
I'd say just put a counter in the room and then increment it.

Or do you mean entering any of the rooms causes all the counters to go up?

Whichever way works.

 Because if you do that, the counters will always have the same value; so you might as well just have a single counter.

Not if you don't start the counters until the player enters in, and then stops 5-10 steps later. Which is what is supposed to happen, even if I don't know how to do it.


See, my problem is that my hell/Dante's Inferno game only makes it so the player only has a 2/5 chance to spawn the monster again, after fighting it once. I just want the probability at 50% like it normally is, unless the player has been there recently, on the last 5 steps, or 10 steps if it's a trainer, in which case it's a 0% chance of spawning.

Here are the codes that I have now, just for reference.
Just to shpw I'm experimenting right now.

Game Start Script

game.spawn = false
game.count2 = 1
game.changedcount2 => {
  switch (game.count2) {
    case (1) {
      game.spawn = false
    }
    case (6) {
      game.count2 = 1
    }
  }
}
game.changedcount3 => {
  if (GetBoolean(game, "notarealturn")) {
    if (player.count2 > 0) {
      msg (game.count2)
    }
    else {
      msg (game.count2 + "+ 1")
    }
  }
}

A few rooms, a few that grow po from thin air...
on enter...

Route 24.changedcount2 => {
  switch (Route 24.count2) {
    case (1) {
      game.spawn = false
    }
    case (6) {
      Route 24.count2 = 1
    }
  }
}
Route 24.count2 = 1
game.changedcount2 => {
  switch (game.count2) {
    case (2) {
      game.spawn = false
    }
    case (6) {
      game.count2 = 1
    }
    case (3) {
      game.spawn = true
    }
  }
}
roll = GetRandomInt(1,100)
if (game.spawn = false) {
  firsttime {
    if (roll > 0 and roll < 26) {
      SpawnSentret (Route 24)
    }
    else if (roll > 25 and roll < 51) {
      SpawnHoothoot (Route 24)
    }
    else if (roll > 50 and roll < 76) {
      SpawnSpinarak (Route 24)
    }
  }
  otherwise {
    if (roll > 0 and roll < 21) {
      SpawnSentret (Route 24)
    }
    else if (roll > 20 and roll < 41) {
      SpawnHoothoot (Route 24)
    }
    else if (roll > 40 and roll < 61) {
      SpawnSpinarak (Route 24)
    }
  }
}
game.count2 = game.count2 + 1
do (game, changedcount3)
firsttime {
  game.spawn = false
}

I can't make much sense out of that code. I'm not sure what the relationship between Route 24.count2and game.count2 is supposed to be; or what the game.spawn flag is for.

I just want the probability at 50% like it normally is, unless the player has been there recently, on the last 5 steps, or 10 steps if it's a trainer, in which case it's a 0% chance of spawning.

Now that is easy enough to do.

You want to track how long it's been since certain rooms have been visited. So let's give those rooms an int attribute steps_since_visited. You could call it "count2" if you really want to, but giving it a name that says what it's for makes life so much easier for anyone who's helping you with your code in future.

Then in your 'roomenter' script ("Script when entering a room:" on the 'scripts' tab of the game) you need to put a short script. This script increases the steps_since_visited counter of any room that has one:

foreach (room, AllObjects()) {
  if (HasInt (room, "steps_since_visited")) {
    room.steps_since_visited = room.steps_since_visited + 1
  }
}

and then in the "on enter" script for Route 24 (or any other room) you can do:

if (HasInt (this, "steps_since_visited")) {
  if (this.steps_since_visited > 5 and RandomChance (50)) {
    // code to determine which pokemon spawns goes here
    // this code will have a 50% chance of running normally, but won't run if they've
    // been here in the last 5 steps
  }
}
this.steps_since_visited = 0

Your code does the same thing my code does, and you posted half of it.


I try to connect game.changedcount3 with Route 24, and that didn't work. It said it didn't know the expression "changedcount3."

Is it possible to connect the th e game start script with the rputes with a name? A stringlist? Is it possible to connect it with anything?


Wait, I think I'm closer!

Route 24.count2 = 1
roll = GetRandomInt(1,100)
if (game.spawn = false) {
  if (Route 24.count2 = 1) {
    firsttime {
      if (roll > 0 and roll < 26) {
        SpawnSentret (Route 24)
      }
      else if (roll > 25 and roll < 51) {
        SpawnHoothoot (Route 24)
      }
      else if (roll > 50 and roll < 76) {
        SpawnSpinarak (Route 24)
      }
    }
    otherwise {
      if (roll > 0 and roll < 21) {
        SpawnSentret (Route 24)
      }
      else if (roll > 20 and roll < 41) {
        SpawnHoothoot (Route 24)
      }
      else if (roll > 40 and roll < 61) {
        SpawnSpinarak (Route 24)
      }
    }
  }
}
game.count2 = game.count2 + 1
firsttime {
  game.spawn = false
}

WAIT! That was not it.

But I think I'm super close to finding it!

Route 24.count2 = 1
roll = GetRandomInt(1,100)
Route 24.divisiblenum = Route 24.count2
Route 24.divisiblenum = Route 24.divisiblenum - 1
if (Route 24.divisiblenum % 5 = 0) {
  msg ("The number is divisible by 5.")
  firsttime {
    if (roll > 0 and roll < 26) {
      SpawnSentret (Route 24)
    }
    else if (roll > 25 and roll < 51) {
      SpawnHoothoot (Route 24)
    }
    else if (roll > 50 and roll < 76) {
      SpawnSpinarak (Route 24)
    }
  }
  otherwise {
    if (roll > 0 and roll < 21) {
      SpawnSentret (Route 24)
    }
    else if (roll > 20 and roll < 41) {
      SpawnHoothoot (Route 24)
    }
    else if (roll > 40 and roll < 61) {
      SpawnSpinarak (Route 24)
    }
  }
}
Route 24.count2 = Route 24.count2 + 1

[Filler text]


Log in to post a reply.

Support

Forums