Wrestling with LC Server and wacky results...?

JOHN PATTEN johnpatten at me.com
Thu Aug 7 00:18:03 EDT 2014


Hi All, 

Still not getting LC server script to record the correct info in a text file. I’m trying recording the last item, item 4, of a players game piece based on the button they are over. Here’s the abbreviated “move game piece script:”
put word 2 of  tLabels into tCurrentSpot --word 2 is a number, ie Button3
   put tCurrentSpot + (cd fld "DiceRoll") into tButton
  
   if tButton > 15 then
      put 1 into tButton
      move cd button tTargetPlayer to the loc of cd button ("Button" && tButton)
      put urlEncode(tTargetPlayer) into tUsername
      put urlEncode("Button" && tButton) into tButtonSpot
      put "username=" & tUsername &"&ButtonSpot=" & tButtonSpot into  tArgList
      
  post tArgList to URL "http://jpatten.on-rev.com/tHidden/moveplayer.lc"
  put  it --into tData

else
      move cd button tTargetPlayer to the loc of cd button ("Button" && tButton)
      put urlEncode(tTargetPlayer) into tUsername
      put urlEncode("Button" && tButton) into tButtonSpot
       put "username=" & tUsername &"&ButtonSpot=" & tButtonSpot into  tArgList
     post tArgList to URL "http://jpatten.on-rev.com/tHidden/moveplayer.lc"
  put  it --into tData
end if

Here’s server script:
<?lc
put $_POST["username"] into tUsername
put $_POST["ButtonSpot"] into tButtonSpot
put url("file:users.txt") into tUsersFile
repeat for each line tLine in tUsersFile
if item 1 of tLine is tUserName then
put tButtonSpot into item 4 of tLine 
--when it gets to spot 10 it is no allowing the 1s spot only the 10s spot, so button "Button 10" shows up as "Button 1," button 11, as Button 1 and so on...
put tLine into tLineNew
put empty into tLine 
put return & tLineNew after tUsersFile
put tUsersFile
end if
end repeat

--open file "users.txt" for write
--write tUsersFile to file "users.txt"
--close file "users.txt"
--put "Moving on!"
--put tUsersFile

?>

The script works fine until player moves up into double digit game spaces, i.e. Button 10, Button 11, etc. However, when I add my changed line as a new line at the bottom of the variable the new line at bottom has the correct two digit button label. So if the player was Luna, and she had just moved to spot “Button 13,” the resulting text file looks like this after the server script runs:

John Patten,secret,jpatten at bmail.com,Button 1
Ivy Patten,1valve,ipatten at bmail.com,Button 5
Sawyer Patten,luna,spatten at bmail.com,Button 1
Luna Patten,secret,mmouse at gmouse.com,Button 6
Sean Patten,secret,spatten at gmouse.com,Button 1
Luna Patten,secret,mmouse at gmouse.com,Button 13

I tried to figure out a way to delete the original line, in this case for Luna where the item 4 is the old labeled Button 6, but couldn’t come up with a script on the server to that.

Tried a couple of the other suggestions too, but know luck. It just seems kind of odd why it will write the correct line to the end of the file, but not to the line in the middle? Any other suggestions?

Thank you!
 John Patten
SUSD






More information about the use-livecode mailing list