mercredi 6 janvier 2016

Creating dynamic objects (Eiffel)

I have to find a way to create objects dynamically, that means the user can decide how many objects to create once the program starts. What I tried to do is:

                if count = 6 then
                create player1.player
                create player2.player 
                create player3.player
                create player4.player
                create player5.player
                create player6.player
                  elseif count > 4 then
                    create player1.player
                    create player2.player 
                    create player3.player
                    create player4.player
                    create player5.player
                      elseif count > 3 then
                        create player1.player
                        create player2.player 
                        create player3.player
                        create player4.player
                          elseif count > 2 then
                            create player1.player
                            create player2.player 
                            create player3.player
                           else
                             create player1.player
                             create player2.player 
               end

Once the user has choosen the number of players, the variable count gets updated and the feature that creates the objects gets called.

I used this kind of brute force method, instead of a loop, because I need the "names" of the objects, I have to called them again in the program.

Anyways the compiler gives me a VEVI error, variable is not properly set. Some help?

Aucun commentaire:

Enregistrer un commentaire