I have a noob problem.

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Mastereve
Posts: 8
Joined: 30 Aug 2011, 23:35

I have a noob problem.

Postby Mastereve » 30 Aug 2011, 23:37

Hello!

I've done everything according to the FPS tutorial and made myself an extension. When i try to call a function from unity i get this in the logs.

Code: Select all

03:41:44,103 ERROR [com.smartfoxserver.v2.controllers.ExtensionController-1] controllers.ExtensionController     -
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NullPointerException
Message: *** Null ***
Description: Error while handling client request in extension: { Ext: SwitchPoker, Type: JAVA, Lev: ROOM, { Zone: SimpleChat }, [ Room: Mircea game, Id: 3, Group: game, isGame: true ] }
Extension Cmd: chip
+--- --- ---+
Stack Trace:
+--- --- ---+
ludis.corePoker.Table.AddChips(Table.java:110)
ludis.corePoker.Table.processUpdateChipCount(Table.java:104)
ludis.handlers.UpdateChipCountHandler.handleClientRequest(UpdateChipCountHandler.java:12)
com.smartfoxserver.v2.extensions.SFSExtension.handleClientRequest(SFSExtension.java:192)
com.smartfoxserver.v2.controllers.ExtensionController.processRequest(ExtensionController.java:137)
com.smartfoxserver.bitswarm.controllers.AbstractController.run(AbstractController.java:96)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:680)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


I have no idea what am i doing wrong so please somebody help.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 31 Aug 2011, 00:45

when you send the 'chip' command it hit on this rule : ludis.corePoker.Table.AddChips(Table.java:110)

Somehting must be wrong there.
Mastereve
Posts: 8
Joined: 30 Aug 2011, 23:35

Postby Mastereve » 31 Aug 2011, 00:47

There all that AddChips() does is adding 20 to chipCount who is public and member of Player.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 31 Aug 2011, 00:51

whats on line Table.java:110 ?
It's hitting on it for some reason...
Mastereve
Posts: 8
Joined: 30 Aug 2011, 23:35

Postby Mastereve » 31 Aug 2011, 00:52

player.chipCount += 20;

Actually is this legal in Java? I am very new to it.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 31 Aug 2011, 00:54

so chipCount is known variable in the player class ?
maybe post the complete file if it's not to long
Mastereve
Posts: 8
Joined: 30 Aug 2011, 23:35

Postby Mastereve » 31 Aug 2011, 00:54

Code: Select all


package ludis.corePoker;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;

public class PokerPlayer {
   
   private Hand hand = new Hand();
   private User sfsUser;
   private int score = 0;
   public int chipCount = 0;
   
   public PokerPlayer(User sfsUser) {
      this.sfsUser = sfsUser;
   }
   
   public void toSFSObject(ISFSObject data) {
      ISFSObject playerData = new SFSObject();

      playerData.putInt("id", sfsUser.getId());
      playerData.putInt("score", this.score);
      playerData.putInt("chipCount", this.chipCount);

      data.putSFSObject("player", playerData);
   }
   
   //accesori
   public Hand getHand() {
      return hand;
   }

   public User getSfsUser() {
      return sfsUser;
   }
   
   //public int getChipCount() {
   //   return chipCount;
   //}
   
   public void Call() {
      //cod pentru acceptarea mizei oferite de alt jucator
   }
   
   public void Raise() {
      //cod pentru marirea mizei propuse de un alt jucator
   }
   
   public void Bet() {
      //cod pentru marirea mizei de catre tine
   }
   
   public void Fold() {
      //cod pentru declinarea ofertei primite
   }
   
   public void ChangeCard() {
      //cod pentru schimbarea unei carti din mana cu cea din mana
      //dealerului
   }
   
}
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 31 Aug 2011, 01:03

I wanted to see the other one, where it's getting the error in : Table.java:110
Mastereve
Posts: 8
Joined: 30 Aug 2011, 23:35

Postby Mastereve » 31 Aug 2011, 01:03

Code: Select all


package ludis.corePoker;

import com.smartfoxserver.v2.entities.User;

import ludis.SwitchPokerExtension;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Date;

public class Table {
   
   private static int minPlayerCount = 3;
   private static Random rnd = new Random();
   
   private SwitchPokerExtension extension;
   
   //Players
   private List<PokerPlayer> players = new ArrayList<PokerPlayer>();
   
   public Table(SwitchPokerExtension extension) {
      
      this.extension = extension;
      rnd.setSeed((new Date()).getTime());
      
   }
   
   public List<PokerPlayer> getPlayers() {
      return players;
   }
   
   private PokerPlayer getPlayer(User u) {
      for(PokerPlayer player: players) {
         if(player.getSfsUser().getId() == u.getId()) {
            return player;
         }
      }
      
      return null;
   }
   
   public boolean addPlayerToTable(User user) {
      
      PokerPlayer player = getPlayer(user);
      player = new PokerPlayer(user);
      players.add(player);
      extension.clientInstantiatePlayer(player);
      
      return true;
      
      
   }
   
   public void userLeft(User user) {
      PokerPlayer player = this.getPlayer(user);
      if (player == null) {
         return;
      }
      players.remove(player);
   }

   public void processCall(User fromUser) {
      
      PokerPlayer player = getPlayer(fromUser);
      
      player.Call();
      
   }
   
   public void processRaise(User fromUser) {
      
      PokerPlayer player = getPlayer(fromUser);
      
      player.Raise();
      
   }
   
   public void processBet(User fromUser) {
      
      PokerPlayer player = getPlayer(fromUser);
      
      player.Bet();
   }
   
   public void processFold(User user) {
      
      PokerPlayer player = this.getPlayer(user);
      
      player.Fold();
   }
   
   public void processChangeCards(User fromUser) {
      
      PokerPlayer player = getPlayer(fromUser);
      
      player.ChangeCard();
   }
   
   public void processUpdateChipCount(User user) {
      
      PokerPlayer player = this.getPlayer(user);
      
      this.AddChips(player);
      extension.clientUpdateChipCount(player);
   }
   
   public void AddChips(PokerPlayer player) {
      
      player.increaseChipCountBy(20);
   }
}


I actually modified it a bit but still same error.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 31 Aug 2011, 01:09

Hard to tell but i'm guessing it's hitting on this function :

public void AddChips(PokerPlayer player) {

player.increaseChipCountBy(20);
}

does the 'increaseChipCountBy' function excist somewhere ?
Mastereve
Posts: 8
Joined: 30 Aug 2011, 23:35

Postby Mastereve » 31 Aug 2011, 01:10

Yes it's in player. Is there any API for writing stuff in the log so i can trace stuff around?
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 31 Aug 2011, 01:13

You can use the trace command : trace ("my debug message");

Your saying that the function excists in the player class... pokerplayer class ?
because i can't see it in the scripts.
Mastereve
Posts: 8
Joined: 30 Aug 2011, 23:35

Postby Mastereve » 31 Aug 2011, 01:14

Code: Select all


package ludis.corePoker;

import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSObject;

public class PokerPlayer {
   
   private Hand hand = new Hand();
   private User sfsUser;
   private int score = 0;
   private int chipCount = 0;
   
   public PokerPlayer(User sfsUser) {
      this.sfsUser = sfsUser;
   }
   
   public void toSFSObject(ISFSObject data) {
      ISFSObject playerData = new SFSObject();

      playerData.putInt("id", sfsUser.getId());
      playerData.putInt("score", this.score);
      playerData.putInt("chipCount", this.chipCount);

      data.putSFSObject("player", playerData);
   }
   
   //accesori
   public Hand getHand() {
      return hand;
   }

   public User getSfsUser() {
      return sfsUser;
   }
   
   public int getChipCount() {
      return chipCount;
   }
   
   public void Call() {
      //cod pentru acceptarea mizei oferite de alt jucator
   }
   
   public void Raise() {
      //cod pentru marirea mizei propuse de un alt jucator
   }
   
   public void Bet() {
      //cod pentru marirea mizei de catre tine
   }
   
   public void Fold() {
      //cod pentru declinarea ofertei primite
   }
   
   public void ChangeCard() {
      //cod pentru schimbarea unei carti din mana cu cea din mana
      //dealerului
   }
   
   public void increaseChipCountBy(int count){
      chipCount += count;
   }
   
}
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Postby appels » 31 Aug 2011, 01:16

yeah now it's in there, if that doesn't work you will need to trace the steps and see where it goes wrong.
The Code looks ok to me unless i missed something :)
Mastereve
Posts: 8
Joined: 30 Aug 2011, 23:35

Postby Mastereve » 31 Aug 2011, 01:41

Found what was causing this. I've traces player and it is null. For some reasons it does't get populated with information.

EDIT Found everything. Thnx for the help. This thread can be closed.

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 7 guests