Cannot find type in scope

hello

I have been working on this problem for 3-4 days and I can’t find the solution.

I can’t declare the variable and I need help to know how I can do it.

I show you my code and if you have an idea I’m interested (I just started and on the tuto I’m doing this is how they declare them)

Hi @Merydian

Welcome to the community.

Where have you declared Heros? (Où avez-vous déclaré “Héros” ?)

I assume that Heros is either a struct or a class but Xcode is not aware of it. (Je suppose que ‘Heros’ est soit un ‘struct’ soit une ‘class’ mais Xcode n’en est pas conscient.)

What Xcode is saying is that it cannot find it anywhere in the project. (Ce que Xcode dit, c’est qu’il ne peut le trouver nulle part dans le projet.).

Translation from Google Translate :grinning:

(edit) Can you include a link to the tutorial please?

Hello

On the tuto that I continue is the chapter for functions but the code that gives us to ‘‘test’’ does not work.

And the ''var enemy = Devil() / is not a declaration of variable

The site is in French so sorry

Without the definition of Heros or Diable the code will not work which is a little disappointing. Does it look like there are parts of the course that are missing?

At a guess it looks like Heros is something like this:

struct Heros {
    var nom: String
    var vie: Int
    var attaque: Int
}

and Diable might be similar

struct Diable {
    var nom: String
    var vie: Int
    var attaque: Int
}

Hello,

Thank you for your answer, I don’t know if there are parts of the course missing but according to my trainer, it is a course that is a little dated so it is possible that because of the updates the ‘‘site’’ is no longer 100% certifiable in short.

Hm so I see you always have to declare your variable according to its type before using it, if I understand correctly?

But on the other hand now the worry is for the loss of life that it is on the side of the ‘‘devil’’ or ‘‘hero’’ I try to understand why the ‘‘enemy and the hero’’ is always considered as ‘‘Cannot find type in scope’’ so I made some test… even if they are going to judge me they will not be able to say that I did not try Hahahahah

If you could just tell me a little bit about where I have to go to find the answer because I don’t want to bother you for such “simple” mistakes for you I think ^^

I show you the part of where I think to declare my attacks and I send you the part of the action in screenshot

Thanks a lot for your help so far! :slight_smile:

To Declare

struct attaquer {
var vie : Int
var ennemi:vie = ennemi.vie - heros.attaque
var heros:vie = heros.vie - ennemi.attaque
}

Action

I also send you the screen of this part, it will be easier to understand

@Merydian

I think this is the problem. The game seems to be incomplete in the tutorial. I don’t understand French very much but using Google Translate it looks like what he is trying to explain is how functions can make things easier especially if you want to attack many times. You just call an attacker… function which changes the property values in heros or ennemi

    func attaquerEnnemi() {
        ennemi.vie = ennemi.vie - heros.attaque // L'ennemi perd de la vie
    }

    func attaquerHero() {
        heros.vie = heros.vie - ennemi.attaque // Le héros perd de la vie
    }

Does that make sense?

You could have a Button in your ViewController where the Hero attacks the enemy and another Button where the enemy attacks the Hero. You could have a number of Labels in the ViewController that displays the status of each of the combatants depending on who attacks who.

I hope that helps.