How to add string togethor

Blitz3D Forums/Blitz3D Beginners Area/How to add string togethor

Gauge(Posted 2003) [#1]
Redone post:
Why does this happen
comm1$="none"
comm2$="not"
comm3$="never"
message$=comm1$+" "+comm2$+" "+comm3$
print "aaa:"+message$

when printedor with writeline i get

aaa: nonotnever

(yeah the spaces come in front of the string!
it should look like aaa:no not never


Rimmsy(Posted 2003) [#2]
this works perfectly for me:

a$="none"
b$="not"
c$="never"

msg$=a+" "+b+" "+c

Print "aaa: "+msg


I can't see why it wouldn't work. Copy and paste this into Blitz (use menu/edit/paste) and see whether it works.


Ross C(Posted 2003) [#3]
works fine here too


Gauge(Posted 2003) [#4]
okay yeah i tested in normally, not sure why it wont work in my program. heres my code!

[code]
Function CommandReader(c.connection)
status=c\status
comm=1
c\comm1$=""
c\comm2$=""
c\comm3$=""
c\comm4$=""
c\message$=""
While ReadAvail(c\stream)
d=ReadByte(c\stream)
Select True
Case d>96
If comm=1 Then c\comm1$=c\comm1$+Chr$(d)
If comm=2 Then c\comm2$=c\comm2$+Chr$(d)
If comm=3 Then c\comm3$=c\comm3$+Chr$(d)
If comm=4 Then c\comm4$=c\comm4$+Chr$(d)
If comm=5 Then c\message$=c\message$+Chr$(d)
Case d=32
c\comm2$=c\comm2$+Chr$(32)
If comm=1 Then comm=2
If comm=2 Then comm=3
If comm=3 Then comm=4
If comm=4 Then comm=5
End Select
Wend
If status=MENU MenuXX C
If status=NEWUSER NewUserX c
If status=SELRACE SelRaceX c
If status=SELCLASS SelClassX c
If status=PLAYING PlayingX c
End Function
Case command$="gossip"
;ks$=Chr$(160)
;comm2$=comm2$+Chr$(32)
;comm3$=comm3$+Chr$(32)
msg$=comm2$+" "+comm3$+" "+comm4$+" "+message$
For a.player=Each player
If a\name$=p\name$ Then
WriteLine p\stream, "You gossip: "+msg$
Else
WriteLine a\stream, p\name$+" gossips "+msg$
EndIf
Next
x=1


Gauge(Posted 2003) [#5]
well i restarted my mud project so its easier for me to use.. this is what i got in the last hour so so, and hour of this thing not working!
AppTitle "MDB-MUD DEMO VERSION 1"
Graphics 600,400,16,3
Color 0,0,255
Global Server
Const Menu=1
Const NewChar1=2
Const NewChar2=3
Const Newchar3=4
Const PlayChar1=5
Const PlayChar2=6
Const Playing=7
Const Logoff=8
Global comm1$
Global comm2$
Global comm3$
Global comm4$
Global message$
Global msg$

Print "MDB-MUD Demon Version 1**********"
Print "Programmed in Blitz Basic! **********"
Print "Written by Michael D. Boruta II*******"
Print "*******************************"

server=CreateTCPServer(4000)
If Not server Then
Print "Server Failed to start on port 4000!"
Print "terminating Program!...sorry!"
Delay 1000
End
Else
Print "Server started! Telnet to port 4000 to play!"
Print "*Now Listening for *Connections**"
Print "Hit the ESCAPE KEY to Shutdown MDB-MUD!"
EndIf

While Not KeyHit(1)
CheckNew
Readstream
Delay 200
Wend

Cls:Text 100,100,"MDB MUD TERMINATED...shutting down!"
Delay 1500
End

Function CheckNew()	
	stream=AcceptTCPStream(server)
	If stream Then
	Print "*CONNECTION RECIEVED*"
	p.player=New player
	p\stream=stream
	p\status=Menu
	WriteLine p\stream, "Welcome to MDB MUD Server!!!"
	WriteLine p\stream, ""
	DisplayMenu p
	EndIf
End Function

Function ReadStream()
	For p.player=Each player
	If Not p\stream Logoff p
	If ReadAvail(p\stream) Then
	CommandReader p
	EndIf
	Next
End Function

Function commandreader(p.player)
	comm=1
		comm1$=""
		comm2$=""
		comm3$=""
		comm4$=""
		message$=""
		While ReadAvail(p\stream)
		d=ReadByte(p\stream)
			Select True
				Case d>32
					If comm=1 Then comm1$=comm1$+Chr$(d)
					If comm=2 Then comm2$=comm2$+Chr$(d)
					If comm=3 Then comm3$=comm3$+Chr$(d)
					If comm=4 Then comm4$=comm4$+Chr$(d)
					If comm=5 Then message$=message$+Chr$(d)
				Case d=32
					If comm=1 Then comm=2 ;And comm1$=comm1$ 
					If comm=2 Then comm=3 ;And comm2$=comm2$
					If comm=3 Then comm=4 ;And comm3$=comm3$
					If comm=4 Then comm=5 ;And comm4$=comm4$
			End Select
			Wend
				comm2$=comm2$+" "
			Print "Command:"+comm2$+" "+"xxx"+"xxx"
			SelectStatus p
End Function

Function DisplayMenu(p.player)
	WriteLine p\stream, ""
	WriteLine p\stream, ""
	WriteLine p\stream, ""
	WriteLine p\stream, "             Main Menu:"
	WriteLine p\stream, "             *********************"
	WriteLine p\stream, "             *                   *"
	WriteLine p\stream, "             * (P)lay Character  *"
	WriteLine p\stream, "             *                   *"
	WriteLine p\stream, "             * (N)ew Character   *"
	WriteLine p\stream, "             *                   *"
	WriteLine p\stream, "             * (W)hos Online     *"
	WriteLine p\stream, "             *                   *"
	WriteLine p\stream, "             * (V)iew Helpfiles  *"
	WriteLine p\stream, "             *                   *"
	WriteLine p\stream, "             *********************"
	WriteLine p\stream, "             *                   *"
	WriteLine p\stream, "             * Your Command:___  *"
	WriteLine p\stream, "             *                   *"
	WriteLine p\stream, "             *********************"
	WriteLine p\stream, "  "
End Function

Function SelectStatus(p.player)
	Select True
	Case p\status=PLAYING 
	Playing p
	Case p\status=Menu 
	Menu p
	Case p\status=NewChar1
	 SelectName p
	Case p\status=NewChar2
	 SelectPassword p
	Case p\status=NewChar3 
	VerifyPassword p
	Case p\status=PlayChar1
	 ValidateName p
	Case p\status=Playchar2 
	Validatepassword p
	Case p\status=Logoff
	 Logoff p
	End Select
End Function

Function Playing(p.player)
command$=comm1$
x=0
Select True
Case command$="gossip"
	;ks$=Chr$(160)
	;comm2$=comm2$+Chr$(32)
	;comm3$=comm3$+Chr$(32)
	msg$=comm2$+comm3$+comm4$+message$
	For a.player=Each player
	If a\name$=p\name$ Then
	WriteLine p\stream, "You  gossip:  "+msg$
	Else
	WriteLine a\stream, p\name$+" gossips  "+msg$
	EndIf
	Next
	x=1
Case command$="quit"
	logoff p
	x=1
Case command$="who"
	wholist p
	x=1
Case command$="recall"
	p\curr_room=000
	WriteLine p\stream, "You recall back to Town Sqaure"
	x=1
Case command$="help"
	WriteLine p\stream, "Sorry, no Helpfiles have been added yet *sniff*"
	x=1
Case command$=""
	WriteLine p\stream, "You look around Town Sqaure wearily"
	x=1
End Select
If x<>1 WriteLine p\stream, "Sorry that command is not yet written!"
End Function

Function Menu(p.player)
Print "Function Menu!"
If comm1$<>"" Then
command$=Left(comm1$,1)
Print command$
EndIf
If command$="n" Then
WriteLine p\stream, "Please choose your name:  "
p\status=NewChar1
EndIf
If command$="w" wholist p
If command$="v" Then
WriteLine p\stream,  "Sorry no helpfiles have been added yet!"
EndIf
If command$="p" Then
WriteLine p\stream,  "What is your characters name?  "
p\status=Playchar1
EndIf
End Function

Function SelectName(p.player)
If command$<>"" Then
WriteLine p\stream, "Sorry your Name must be at least 3 characters long...try again."
Else
p\name$=comm1$
WriteLine p\stream, "Welcome  to MDB MUD!!!"+p\name$
WriteLine p\stream, "What password would you like?  "
p\status=NewChar2
EndIf
End Function

Function SelectPassword(p.player)
If comm1$<>"" Then
p\password$=comm1$
WriteLine p\stream,  "Please Verifty that your password is:  "+p\password$
p\status=NewChar3
Else 
WriteLine p\stream,  "Sorry password not accepted!"
EndIf
End Function

Function VerifyPassword(p.player)
checkpw$=comm1$
If comm1$=p\password$ Then
WriteLine p\stream,"Password Verified....You are now Playing"
p\status=PLAYING
startup p
Else
WriteLine p\stream, "Sorry the passwords did not match, please try again!"
p\password$=""
p\status=NewChar2
WriteLine p\stream, "Please try another password:"
EndIf
End Function

Function Validatename(p.player)
End Function

Function Validatepassword(p.player)
End Function

Function Startup(p.player)
	p\curr_room=000
	WriteLine p\stream, "This is a test server, Races,Classes, Areas, etc are not in yet"
	WriteLine p\stream, "The following commands are in(case sensitive too"
	WriteLine p\stream, "quit recall who help gossip"
	WriteLine p\stream, "almost in: north south east west ne se sw se up down look(room only)"
	WriteLine p\stream, "almost in: say tell whois look(someone), look(object), cast"
	WriteLine p\stream, "almost in: helpfiles, spell,skill.score,stat"
	WriteLine p\stream, "Please enjoy the game, hopefully will soon be completed"
	WriteLine p\stream, "New areas, etc etc will always be added...Thank you for playing!"
	WriteLine p\stream, "Welcome to Town Sqaure"
End Function

Function logoff(p.player)
	If p\stream Then
	WriteLine p\stream, "GOODBYE!...come back soon!"
	EndIf
	CloseTCPStream(p\stream)
	Delete p
	
End Function

Function Wholist(p.player)
	WriteLine p\stream, "Players found:"
	c#=0
	For a.player=Each player
	c#=c#+1
	WriteLine p\stream, "Level 50: "+p\name$+"   "+p\title$
	Next
	WriteLine p\stream, "Total players found:  "+c#
End Function

Type player
Field stream
Field status
Field name$
Field password$
Field Title$
Field curr_room
End Type



Gauge(Posted 2003) [#6]
p.s you'd need to telnet over to your ip address, i use zmud, and use n to create a new char, choose name, type password twice, and then gossip once you are "playing" to see its not working, perhaps its cause i'm changing functions?? i also tried it without using p\comm1$, and just using comm1$,etc, but to no avail *sigh*


WolRon(Posted 2003) [#7]
First of all, why not replace all of this:
Case d=32
  If comm=1 Then comm=2 ;And comm1$=comm1$ 
  If comm=2 Then comm=3 ;And comm2$=comm2$
  If comm=3 Then comm=4 ;And comm3$=comm3$
  If comm=4 Then comm=5 ;And comm4$=comm4$

with just this:
Case d=32
  comm = comm + 1


I'm not exactly sure what you are trying to accomplish.

Here you are adding a space to the end of the comm2$ variable but you don't do the same for any of the other variables (comm1$, comm3$, etc.)
comm2$=comm2$+" "


And here you are printing a space after comm2$ (even though you added a space to comm2$ earlier) but you don't put any spaces between the other texts.
Print "Command:"+comm2$+" "+"xxx"+"xxx"


I really don't understand your problem OR what you are trying to do.
You should try stepping through your program with debug enabled.