Home » Community » Forums » For Beginners » Question!
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Question!
Post New Topic  Post Reply 
Hey, I was just wondering if their is anyway to create an array within a user-defined method.

What i want to do is get some users names and total amounts of votes they got for an election. the problem I am having is that when i go to set the name and the total votes into the arrays through the method, I can't print them out in the main class then? It acts as if the arrays only exist within that method and I dont know how to change that..

I dont really know how to explain it but if anyone understands what i'm getting at it would be very helpful.

 User Rating: 1011   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

You probably can. But we would need to know what language you are using to give you concrete advice. You could post your code too, if its not long enough.


blog

 User Rating: 1920   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Hey!

Maybe you should paste the code of what you have done so far, and tell us which language you are using. People will understand the problem better if you do.

 User Rating: 1039   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

If his(?) other threads are any indication, Java. And he needs to review the chapter discussing scope...

 User Rating: 1814   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Scope.

Look at this code (yours, probably):
class Something
{
   int Main()
   {
      // array does not exist within this method
   } 
   int UserDefined()
   { 

      Array arrayVisibleOnlyToUserDefined;
 
      // Here you can use array
   }
}



and this code (working):

class Something
{
   Array arrayVisibleToAllMethodsWithinSomething;
   int Main()
   {
      // Here you can use array
   } 
   int UserDefined()
   {
      // Here you can use array
   }
}



Variables (including Array) are only visible within the code block ( delimited by { and } ) they are declared in. Hope this helps. And improve your grammar (dont -> don't; i -> I).

--------
Join the UFEC Game Programming Contest!

 User Rating: 1173   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Lesan you are right. I was trying to instansiate the array in the main when it has to be before it...stupid little mistake on my part.

Thanks guys!

and it was in JAVA

 User Rating: 1011   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may not post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: