[Gamesnws-commits] r15 - pkg/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 16 14:36:38 CEST 2009


Author: schmidb
Date: 2009-07-16 14:36:37 +0200 (Thu, 16 Jul 2009)
New Revision: 15

Modified:
   pkg/R/playUno.R
Log:
bug fix with list objects and strsplit (error input)

Modified: pkg/R/playUno.R
===================================================================
--- pkg/R/playUno.R	2009-07-16 09:23:17 UTC (rev 14)
+++ pkg/R/playUno.R	2009-07-16 12:36:37 UTC (rev 15)
@@ -91,6 +91,7 @@
 				cards_hand <- c(cards_hand, nwsFetchTry(ws,"cards"), nwsFetchTry(ws,"cards"),nwsFetchTry(ws,"cards"), nwsFetchTry(ws,"cards"))
 				nwsStore(ws, user, cards)
 			}
+			cards_hand <- nwsFindTry(ws, user)
 			cat("Hand:", sort(unlist(cards_hand)), "\n") #sorted output
 			
 			# PLAY CARD
@@ -180,6 +181,8 @@
 	} else{
 		# for user
 		card_play <- readline("Play: ")
+		# TODO 
+		# check ob gültige karte
 		# ask for
 		if(card_play=="rybg-0"){
 			# ask for color by wish card
@@ -202,8 +205,12 @@
 {
 	require(nws)
 	#split for color and number
-	card_play_color <- strsplit(card_play_save, "-")[[1]][1]
-	card_play_number <- strsplit(card_play_save, "-")[[1]][2]
+	tmp <- strsplit(card_play_save, "-")
+	card_play_color <- tmp[[1]][1]
+	if( is.na(tmp[[1]][2]) )
+		card_play_number <- ""
+	else
+		card_play_number <- tmp[[1]][2]
 	played_color <- strsplit(unlist(played), "-")[[1]][1]
 	played_number <- strsplit(unlist(played), "-")[[1]][2]
 	
@@ -341,5 +348,5 @@
 	} else
 		warning("Error : unknown use case!")
 	
-	return(card_play, NO)
+	return(list(card_play, NO))
 }
\ No newline at end of file



More information about the Gamesnws-commits mailing list