Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

help!! drop spawner BCE0005: Unknown identifier: 'i'

Discussion in 'Scripting' started by giani91, Nov 19, 2015.

  1. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    I am creating a game for android in unity 5 and I need to use this script , I used formerly with Unity 4.5 but now does not work

    Code (CSharp):
    1.  
    2. var spawnPoints : Transform[];  // Array of spawn points to be used.
    3. var Prefabs : GameObject[]; // Array of different Enemies that are used.
    4. var amount = 20;  // Total number of enemies to spawn.
    5. var yieldTimeMin = 2;  // Minimum amount of time before spawning enemies randomly.
    6. var yieldTimeMax = 5;  // Don't exceed this amount of time between spawning enemies randomly.
    7.  
    8. function Start(){
    9.     Spawn();
    10. }
    11.  
    12. function Spawn(){
    13.    for (i=0; i<amount; i++){
    14.       yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax));
    15.  
    16.       var obj : GameObject = Prefabs[Random.Range(0, Prefabs.length)];
    17.       var pos: Transform = spawnPoints[Random.Range(0, spawnPoints.length)];
    18.  
    19.       Instantiate(obj, pos.position, pos.rotation);
    20.     }
    21. }
    22.  

    I tried everything but I managed to solve the problem

    please guys help me
     
  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    What's the full error message on the console?
     
  3. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You've forgotten to declare the variable 'i' in the loop.
    Try
    Code (JavaScript):
    1. (var i=0; i<amount; i++){
    or:
    Code (JavaScript):
    1. (int i=0; i<amount; i++){
    instead of
    Code (JavaScript):
    1. (i=0; i<amount; i++){
     
  4. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15

    the full error message say:

    assets/dropspawner.js(13,9): BCE0005: Unknown identifier: 'i'.
     
  5. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    dont work man :(
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    The most common, least helpful phrase on the forums. "Doesn't work" doesn't say anything. Different error message? Same error message? Also, there were two suggestions given there, which one did you try? or did you try both?

    ("var i" is absolutely and exactly the solution, btw, so if you tried that and you're still getting the same error...maybe you forgot to hit save? Don't know what else to tell you)
     
  7. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15


    I am new to unity and not used very well could you help me create the script that is to say that I did not know how to correct the problem with your suggestion
     
  8. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Exactly what @Suddoha suggested. The first suggestion, in particular (the second one would only work in C#). I honestly don't think I can make it any clearer than he did.
     
  9. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15

    i use var i and the message say:

    Assets/dropspawner.js(1,2): BCE0043: unexpected token: var and other look the pic

    i use this script wih your modification

    Code (CSharp):
    1. (var i=0; i<amount; i++){
    2. var spawnPoints : Transform[];  // Array of spawn points to be used.
    3. var Prefabs : GameObject[]; // Array of different Enemies that are used.
    4. var amount = 20;  // Total number of enemies to spawn.
    5. var yieldTimeMin = 2;  // Minimum amount of time before spawning enemies randomly.
    6. var yieldTimeMax = 5;  // Don't exceed this amount of time between spawning enemies randomly.
    7.  
    8. function Start(){
    9.     Spawn();
    10. }
    11.  
    12. function Spawn(){
    13.    for (i=0; i<amount; i++){
    14.       yield WaitForSeconds(Random.Range(yieldTimeMin, yieldTimeMax));
    15.  
    16.       var obj : GameObject = Prefabs[Random.Range(0, Prefabs.length)];
    17.       var pos: Transform = spawnPoints[Random.Range(0, spawnPoints.length)];
    18.  
    19.       Instantiate(obj, pos.position, pos.rotation);
    20.     }
    21. }  
     

    Attached Files:

  10. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    and sorry for my english jaja i live in Panama and speak in spanish
     
  11. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Where's your "for" at the start of your (var i = 0.....) part at the beginning of your code?

    And where's your brackets? The first 6 lines of your code is meaningless and error-prone.
     
  12. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    Sorry, you could modify my script? active command would try
     
  13. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    the START be in the 8 line, the function Start for the Script

    @asperatology
     
  14. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    i wanna help to other gays with this problem because im new in this and
    I know how hard it is to start using a new program
     
  15. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
  16. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    a little, I 'm studying in the university
    I'm in second half
     
  17. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    CS, ECE, RBE, MIS, anything? Anything related to computers?

    Go here instead.
     
  18. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    thank you man,

    and sure, but you think you can fix the script
     
  19. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    its a simple script i need spawner objets

    i have 3 months with this proyect and i wanna to learn
     
  20. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Remove Line 1~6, and Line 14 in the code given above.
     
  21. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    ohhh yeah man thank you
    Thanks , it was just a rookie mistake and I solved thanks to you
     
  22. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    If you want to learn to use Unity, start here
    https://unity3d.com/learn/tutorials

    Asking people to fix your scripts for you, when they gave you the solution, won't help you learn.
     
  23. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This whole thread is a rookie mistake. The first thing you should do is spend 3 months on the Learn section, but it doesn't appear you're serious enough about Unity for me to help so best of luck.
     
  24. giani91

    giani91

    Joined:
    Nov 19, 2015
    Posts:
    15
    I know but I felt very frustrated at not being able to fix the problem