Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to catch pokemon #245

Open
davidmottet opened this issue Aug 16, 2016 · 7 comments
Open

Impossible to catch pokemon #245

davidmottet opened this issue Aug 16, 2016 · 7 comments

Comments

@davidmottet
Copy link

davidmottet commented Aug 16, 2016

I have this message when i try to catch pokemon
Encountering pokemon Psyduck... Encountering pokemon Rhyhorn... Encountering pokemon Magikarp... Encountering pokemon Exeggcute... { Status: null, MissPercent: null, CapturedPokemonId: null, CaptureAward: null } undefined undefined undefined

Can you help me?

@monarchfish
Copy link

let me see your code

@davidmottet
Copy link
Author

davidmottet commented Aug 17, 2016

It's the same with exemple code :/

@monarchfish
Copy link

I think maybe it's goes too fast.
you need to make some delay between every EncounterPokemon and CatchPokemon.

@davidmottet
Copy link
Author

Same results

[+] There is a Magikarp near!! I can try to catch it!
[+] There is a Eevee near!! I can try to catch it!
[+] There is a Magikarp near!! I can try to catch it!
[+] There is a Rattata near!! I can try to catch it!
[+] There is a Magikarp near!! I can try to catch it!
Encountering pokemon Magikarp...
{ Status: null,
  MissPercent: null,
  CapturedPokemonId: null,
  CaptureAward: null }

To do that when there are pokemons catchable I engage one by one

@monarchfish
Copy link

I think is the same problem, how do you put your delay between them?

@ameyer
Copy link

ameyer commented Aug 23, 2016

Basically you have to wait for your API call to complete before you do another. So in the for loop looking for catchable pokemon, I exit the loop (either return or break) when I find one so it wont go on to the next one until the next heartbeat.

Something like this (I striped out a ton of code for this so I don't know if this works on its own)

function heartbeat(){
    pokeAPI.Heartbeat(function(err,hb) {

        //Find catchable pokemon & catch them if we can
        for (i = hb.cells.length - 1; i >= 0; i--) {
            for (var j = hb.cells[i].MapPokemon.length - 1; j >= 0; j--){
                var currentPokemon = hb.cells[i].MapPokemon[j];
                //found one we can get, GET IT!
                getCurrentPokemon(currentPokemon);
                return;
            }
        }
    });
}

function getCurrentPokemon(currentPokemon){
    pokeAPI.EncounterPokemon(currentPokemon, function(suc, dat) {

        normalized_reticle_size = 1.95;
        spin_modifier = 1;
        normalized_hit_position = 1;
        pokeBallType = 1;

        //throw the ball
        pokeAPI.CatchPokemon(currentPokemon, normalized_hit_position, normalized_reticle_size, spin_modifier, pokeBallType.id, function(err, result) {
            var status = ['Unexpected error', 'SUCCESSFUL CATCH !!!', 'Catch Escape', 'Catch Flee', 'Missed Catch'];                
            console.log(status[result.Status]);             
        });
    }); 

}

@rudemex
Copy link

rudemex commented Aug 23, 2016

sorry, my englis is not very good... i write in spanish.

cree una variable global

var isCatch = false;

y lo que hago es verificar si estoy atrapando uno, que no atrape otro. utilizando un simple IF

a.EncounterPokemon(currentPokemon, function(suc, dat) {
if(!isCatch){
isCatch = true;
console.log('Encountering pokemon ' + pokedexInfo.name + '...');
a.CatchPokemon(currentPokemon, 1, 1.950, 1, 1, function(xsuc, xdat) {
var status = [
'Unexpected error',
'Successful catch',
'Catch Escape',
'Catch Flee',
'Missed Catch'
];
isCatch = false;
console.log(status[xdat.Status]);
//console.log(xdat.Status);
});
}
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants