Thread: Python Troubles

Results 1 to 3 of 3
  1. #1 Python Troubles 
    Registered Member Mini's Avatar
    Join Date
    Jul 2007
    Posts
    285
    Thanks given
    5
    Thanks received
    7
    Rep Power
    35
    Hello all -

    I'm trying to convert this simple python to java but I feel like I'm doing something wrong.

    Code:
    def npcInteractOptionOne_Captain_Bentley(player, *npc):
    	session = WiseOldMan(player, npc)
    	session.initiate()
    More specifically, I can't call this in Java like this:

    Code:
    	DialogueSession session = new CaptainBentley(p, npc);
    	session.initiate();
    because CaptainBentley.java expects these arguments

    Code:
        public CaptainBentley(Player player, NPC[] actors)
        {
            super(player, actors);
            this.npc = actors[0];
        }
    so how is the python script passing a single NPC to a class that expects an array? And what does *npc mean in this context? A list of NPCs (such as an array)?

    Feel like this is such a dumb question that even google can't help me :/

    Thanks,
    -Mini
    Reply With Quote  
     

  2. #2  
    Contributor

    clem585's Avatar
    Join Date
    Sep 2013
    Posts
    3,788
    Thanks given
    706
    Thanks received
    702
    Rep Power
    570
    Quote Originally Posted by Mini View Post
    Hello all -

    I'm trying to convert this simple python to java but I feel like I'm doing something wrong.

    Code:
    def npcInteractOptionOne_Captain_Bentley(player, *npc):
    	session = WiseOldMan(player, npc)
    	session.initiate()
    More specifically, I can't call this in Java like this:

    Code:
    	DialogueSession session = new CaptainBentley(p, npc);
    	session.initiate();
    because CaptainBentley.java expects these arguments

    Code:
        public CaptainBentley(Player player, NPC[] actors)
        {
            super(player, actors);
            this.npc = actors[0];
        }
    so how is the python script passing a single NPC to a class that expects an array? And what does *npc mean in this context? A list of NPCs (such as an array)?

    Feel like this is such a dumb question that even google can't help me :/

    Thanks,
    -Mini
    Code:
    DialogueSession session = new CaptainBentley(p, new NPC[] { npc });
    Project thread
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member Mini's Avatar
    Join Date
    Jul 2007
    Posts
    285
    Thanks given
    5
    Thanks received
    7
    Rep Power
    35
    Quote Originally Posted by clem585 View Post
    Code:
    DialogueSession session = new CaptainBentley(p, new NPC[] { npc });
    I had something like this but it wasn't right. Appreciate it! I assume this is just creating the array and adding the npc to it? Need to get these basics down :/

    Quote Originally Posted by jhg023 View Post
    This can be a solution, however it can be a little more simple. OP, the asterisk in Python represents varargs, which in Java is represented by "..."

    Code:
    public CaptainBentley(Player player, NPC... npcs)
    You can then add any any amount of NPCs without explicity defining an array.
    Interesting... I'll do some further reading on varargs. Very helpful.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 24
    Last Post: 11-02-2009, 03:06 PM
  2. Having trouble.
    By Vice in forum Software
    Replies: 6
    Last Post: 08-18-2008, 08:12 AM
  3. Web Server/Python
    By Game in forum Application Development
    Replies: 4
    Last Post: 06-30-2008, 05:33 PM
  4. sig trouble
    By Joe in forum General
    Replies: 4
    Last Post: 12-18-2007, 12:51 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •