Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with MID$ and LEN
#1
Hi.

- I got two SUB's, one that writes out a message in the shape of a string called text$ (SUB PrintMsg) and one that creates this string (SUB MsgWriting).

- The string can be as long as 8 x 50 characters, defending on how many enemies that hits you at the same time ( from 1 to 8 enemies can strike the player at the same time).

- I wan't the program to display each enemy-attack per line (one line of information, then PressAnyKey and then the next enemy-attack and so on).

- Right now, I've tried to make it so each enemy-attack-text-message get's 50 character (the engine adds spaces until the message reached 50 character)


Code below: Both SUB's have been cuted, but they display what's needed. And yes, mmonattacktext$ = text$

Code:
SUB printmsg (text$)

LOCATE 1, 1: PRINT SPACE$(79)

IF LEN(text$) < 79 THEN                                                      
LOCATE 1, 1: PRINT text$                                                  
ELSE                                                                        
                                                                            
textstart = 1                                                          
textlenght = 50                                                            

FOR x = 1 TO LEN(text$) / 50                                                  
showtext$ = MID$(text$, textstart, 50)                              
LOCATE 1, 1: PRINT showtext$ + " -more-": pak: LOCATE 1, 1: PRINT SPACE$(79)
textstart = textstart + 50                                                  
NEXT x                                                                      
                                                                          
END IF                                                                      

END SUB


SUB MsgWriting ()

FOR  monnumatt = 1 to numenemies

a$ = RTRIM$(Monster(MonNum).MName)
damage = Rand(MAttacks(MonAttNum).AttackDice, MAttacks(MonAttNum).AttackDice * MAttacks(MonAttNum).AttackSides)

monattacktext$ = a$ + " " + RTRIM$(MAttacks(MonAttNum).AttackDesc) + " you for " + LTRIM$(STR$(damage)) + " damage! "
mmonattacktext$ = mmonattacktext$ + monattacktext$ + SPACE$(50 - LEN(monattacktext$))

      Player.ptemphitpoints = Player.ptemphitpoints - damage

ELSE

a$ = RTRIM$(Monster(MonNum).MName)

   monattacktext$ = a$ + " misses You! "
  mmonattacktext$ = mmonattacktext$ + monattacktext$ + SPACE$(50 - LEN(monattacktext$))

  END IF

  NEXT monnumatt
END IF


END SUB
[Image: jocke.gif]
Website: http://jocke.phatcode.net
"Some men get the world, other men get ex hookers and a trip to Arizona."
Reply
#2
So what's the problem?

Do you want to take one string and print them with a maximum length? Is that it?
Do you want to actually have a carriage return (enter?)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#3
doh...sorry, I fixed it myself. Sorry again :oops:

The problem I had (and also the thing I forgot to mention) was in the SUB PrintMsg: The code forced the player to PressAnyKey even if the sub was displaying the last 50 character of text from text$.

Anyways, it's fixed...thanks anyway.. *jocke blushes and then walks away in the sunset...* :wink:
[Image: jocke.gif]
Website: http://jocke.phatcode.net
"Some men get the world, other men get ex hookers and a trip to Arizona."
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)