Results 1 to 8 of 8

Thread: [2005] String

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    96

    [2005] String

    Let me explain what I say
    I am making a game
    there are 2 characters.
    And I make a class called character
    dim char1 as new character
    dim char2 as new character
    And I make a function

    Function result(i as integer) as integer
    char1.sth.....
    char2.sth

    But I don't want to write each line of code twice....
    And I write that char & i ,but it can't work
    what should I do?
    Last edited by s021126; May 31st, 2007 at 09:36 AM.

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: [2005] String

    Quote Originally Posted by s021126
    abc.ab1
    abc.ab2

    for i = 1 to 2
    abc.ab & i = "...."

    What's wrong?
    Thx
    How about trying to explain what you are trying to do?

    Using arrays would be helpful in your case.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    96

    Re: [2005] String

    Public Shared char1 As New sprite("char1")

    spirte is a class

    And I cant use array in this case

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: [2005] String

    Quote Originally Posted by s021126
    Public Shared char1 As New sprite("char1")

    spirte is a class

    And I cant use array in this case
    You have still not explained what you are trying to do?

    And why can't you use Arrays?
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  5. #5
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] String

    You cannot access Properties/Methods/events of a class using enumeration. You have to access them by name.

    Myclass.Property1 = x
    Myclass.Property2 = x

    When you declare a new class object:

    Public _myclass as New Myclass

    you then use this to access the properties:

    _myclass.Property1 = x
    _myclass.Property2 = x

    If you have defaults for class properties that you want to set with ANY new instantiation (spelling??) of that class then you set it up like this (in the class itself):
    Code:
    Public Sub New()
    Property1 = x
    Property2 = x
    End Sub
    You can also set New to accept arguements and overload itself:
    Code:
    Public Sub New(ByVal String1 as String, ByVal Int1 as Integer)
    
    Property1 = String1
    Property2 = Int1
    
    End Sub
    If you already know all of this, then I apologize but I saw what you posted and thought this information may be of some use.

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Posts
    96

    Re: [2005] String

    Let me explain what I say
    I am making a game
    there are 2 characters.
    And I make a class called character
    dim char1 as new character
    dim char2 as new character
    And I make a function

    Function result(i as integer) as integer
    char1.sth.....
    char2.sth

    But I don't want to write each line of code twice....
    And I write that char & i ,but it can't work
    what should I do?

  7. #7
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: [2005] String

    I do not believe there is any way around this with individual variables.

    The only thing I can come up with is to create an array of characters and use a for loop to access each one in the array and set the property once:
    Code:
    For i as integer = 0 to array.length-1
      array(i).PropertyName = FunctionName(Byval ParameterName as Type)
    Next
    Did that on the fly so it will probably need tweaking, but am hoping that it gives you a general idea....

    Good Luck!!

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  8. #8
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] String

    Quote Originally Posted by s021126
    Let me explain what I say
    I am making a game
    there are 2 characters.
    And I make a class called character
    dim char1 as new character
    dim char2 as new character
    And I make a function

    Function result(i as integer) as integer
    char1.sth.....
    char2.sth

    But I don't want to write each line of code twice....
    And I write that char & i ,but it can't work
    what should I do?
    If you dont want to write each line over and over again, you would need a loop. And what does a loop need? Something to loop through; an array or a collection. You would need to create one of those and populate it with your instances of the character class.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width