Hi All
This is my first ever post to the forum but your query happened to coincide with some stuff I'm playing around with.
Your code is doing two things:
The value for the last letter in the player name string is being over written by (the length of the level name string - 1), then being printed to screen as a character.
This is happening here:
inc t:write memblock byte 1,t,len(levelname$)
All you've done is got the position in the mem block wrong. To fix the position you need to increment t by 2. However, this causes another problem which I couldn't quite figure out.
The second problem is that an extra "l" is being added to the end of the level name string in each loop but I couldn't find where the program was doing this.
Both these problems can be seen if you run this code.
sync on
sync rate 60
backdrop on
color backdrop 0
hide mouse
iam$="host"
playername$="TheComet"
levelname$="media\models\levels\underground.lvl"
joined=2
maxplayers=30
do
rem if host, send game info to everyone at regular intervals
if iam$="host"
inc ccc:if ccc>30
make memblock 1,len(playername$)+len(levelname$)+6
write memblock byte 1,0,joined
write memblock byte 1,1,maxplayers
write memblock byte 1,2,len(playername$)
for t=1 to len(playername$)
write memblock byte 1,t+2,asc(right$(left$(playername$,t),1))
next t
inc t:write memblock byte 1,t,len(levelname$)
inc t
for r=t to len(levelname$)+t
write memblock byte 1,r,asc(right$(left$(levelname$,r),1))
next r
t=r+1
write memblock byte 1,t,0
rem send net message memblock 0,1,1
joined=memblock byte(1,0)
maxplayers=memblock byte(1,1)
s$=""
s=memblock byte(1,2)
for t=1 to s
s$=s$+chr$(memblock byte(1,t+2))
next t
playername$=s$
s$=""
s=memblock byte(1,t+1)+t
for r=t to s
s$=s$+chr$(memblock byte(1,r+2))
next r
levelname$=s$
endloop=memblock byte(1,r+1)
rem delete memblock 1
delete memblock 1
host$=playername$
ccc=0
endif
endif
rem extract level name from level path
dob=0
letr=0
repeat
inc letr
s$=left$(right$(levelname$,letr),1)
if s$="\" then inc dob
until dob=1 or letr>1000
levelnamep$=right$(levelname$,letr-1)
rem game info
text 400,20,"Game Info"
text 400,32,"========="
text 400,50,"Host : "+host$
text 400,62,"Players Joined : "+str$(joined)
text 400,74,"Maximum Players : "+str$(maxplayers)
text 400,86,"Map Name : "+levelnamep$
text 1,98,"length of level name string: "+str$(len(levelnamep$))
text 1,110,"character based on length of level name string: "+chr$(len(levelnamep$) - 1)
sync
loop
The only thing I have done here is to add on two extra line that print the length of the level name string and the last character of the player name string that is being constantly over written.
I think part of the main problem is that the place in the memblock where you store the length of the level name moves depending on the length of the player name string, which in itself shouldn't be causing a problem but is a little confusing when trying to work out where all the data is in the memblock.
Taking a cue from how memblocks for meshes etc are created, I've restructured your memblock to include a header, mainly so that there is a value that shows where the position of the level name data is stored in the memblock, which makes it easier to locate. If lashed up some code to show how this works:
sync on
sync rate 5
backdrop on
color backdrop 0
hide mouse
iam$="host"
playername$="James"
levelname$="drive\folder\subfolder\filename.lvl"
joined=2
maxplayers=30
do
`create the memblock
make memblock 1,len(playername$)+len(levelname$)+6
`memblock header
write memblock byte 1,0,joined
write memblock byte 1,1,maxplayers
write memblock byte 1,2,len(playername$)
write memblock byte 1,3,len(levelname$)
write memblock byte 1,4,len(playername$)+4: `position of level name data
`write player name to memblock
for t=1 to memblock byte(1,2)
write memblock byte 1,t+4,asc(right$(left$(playername$,t),1))
next t
`write level name to memblock
for t = 1 to memblock byte(1,3)
write memblock byte 1, t + memblock byte(1,4), asc(right$(left$(levelname$,t),1))
next t
`extract first two rows of header from memblock
number_of_players_joined = memblock byte(1,0)
max_number_of_players = memblock byte(1,1)
`extract player name from memblock
name_of_player$ = ""
for t = 1 to memblock byte(1,2)
letter$ = chr$(memblock byte(1,t+4))
name_of_player$ = name_of_player$ + letter$
next t
`extract level file path / name from memblock
file_path_of_level$ = ""
for t = 1 to memblock byte(1,3)
position_of_level_name = memblock byte(1,4)
letter$ = chr$(memblock byte(1, position_of_level_name + t))
file_path_of_level$ = file_path_of_level$ + letter$
next t
`extract level name from level file path
level_name$ = ""
s$ = ""
letr = 0
dob=0
repeat
inc letr
s$=left$(right$(file_path_of_level$,letr),1)
if s$="\" then inc dob
until dob=1 or letr>1000
level_name$=right$(file_path_of_level$,letr-1)
delete memblock 1
`print stuff out
set cursor 1,1
`print first two lines of header
print "number_of_players_joined = ", number_of_players_joined
print "max_number_of_players = ", max_number_of_players
`print player's name
print "name_of_player$ = ", name_of_player$
`print file path of the level
print "file_path_of_level$ = ", file_path_of_level$
print "level_name$ = ", level_name$
sync
loop
I hope this is of some help.