Topic:   String Commands   (Read 9481 times)


0 Members and 1 Guest are viewing this topic.

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
String Commands
« on: December 06, 2010, 06:40:26 PM »

You think this is easier then?
Code: [Select]
LET mapArray$(1) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(2) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(3) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(4) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0"
LET mapArray$(5) = "0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0"
LET mapArray$(6) = "0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0"
LET mapArray$(7) = "0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0"
LET mapArray$(8) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0"
LET mapArray$(9) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(10)= "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"


« Last Edit: December 06, 2010, 10:42:21 PM by Connors »
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Charlo


  • GMG-er

  • **


  • Posts: 451
Re: String Commands
« Reply #1 on: December 06, 2010, 09:18:11 PM »
The parameters for NTHFIELD are the string being processed, the delimiter, and the number of the field you want to retrieve.

Example:
Code: [Select]
LET x$ = NTHFIELD(map$, ", ", 3)
'gets the third item out of map$, which has values separated by commas
'if map$ was "5, 3, 2, 8, 12" the above code would put the value "2" in x$ (note that it would still be a string)

Your code looks a little weird to me.  It seems like you're combining SC arrays with GM-style map reading.  I would just have each 0 or 1 stored in its own array slot.  But if you're going to do it that way, to check for enemies, you would have to loop through each item of the array and then, within that loop, loop through the characters in the string.

Pseudocode with some SC commands:
Code: [Select]
FOR x = 0 to COUNTARRAY(array)
 Â  FOR y = 0 to COUNTFIELDS(array[x])
 Â     'do stuff here using NTHFIELD(array[x], " ", y)
 Â  NEXT
NEXT
« Last Edit: December 06, 2010, 09:19:52 PM by Charlo »

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: String Commands
« Reply #2 on: December 06, 2010, 10:43:11 PM »
LOL ok i accidentally changed the 1st post, you think that is easier to handle then?

EDIT:

Code: [Select]
DIM mapArray$(10)

LET mapArray$(1) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(2) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(4) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(5) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(6) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(7) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(8) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(9) = "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
LET mapArray$(10)="0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"


FOR y = 0 to 9
   FOR x = 1 to 19
      LET type$ = NTHFIELD$(mapArray$(y), ", ",x)
   NEXT
NEXT

error: array out of bounds
(line 16, the NTHFIELD$ command)
« Last Edit: December 06, 2010, 11:02:20 PM by Connors »
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Charlo


  • GMG-er

  • **


  • Posts: 451
Re: String Commands
« Reply #3 on: December 07, 2010, 07:41:14 AM »
For that code to work you would have to do the first loop as "FOR y = 1 to 10" since arrays in SC start at one.  ;)

I would do something like
Code: [Select]
LET mapArray(1) = 0
LET mapArray(2) = 0
LET mapArray(3) = 1
so I wouldn't need to combine string functions and array functions.  I think I would just end up confusing myself.  You could always put your map string in one string variable and then parse it out into an array doing something like this:
Code: [Select]
LET mapString = "0,1,0,1,1,0,0,0,0,0,0,0"
FOR x = 1 to COUNTFIELD(mapString)
mapArray(x) = NTHFIELD(mapString, ", ", x)
NEXT
« Last Edit: December 07, 2010, 07:43:03 AM by Charlo »

EqwanoX


  • Administrator

  • GMG Extraordinaire

  • *****


  • Posts: 1180
Re: String Commands
« Reply #4 on: December 07, 2010, 07:59:23 AM »
what exacly are you trying to do?

if you used the mid$ command, then you wouldnt need the commas

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: String Commands
« Reply #5 on: December 07, 2010, 01:00:07 PM »
OK, good to know. I'm basically trying to make a constantly scrolling level, but mostly I want to make enemies appear on command. However, I'd like to add map tiles for obstacles, like the ground and mines and cliffs etc.
I'm re-working it a little so it makes more sense, so I'll let you know when I hit more problems. How does "mid$" work? :(
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: String Commands
« Reply #6 on: December 07, 2010, 01:10:41 PM »
The mid$ command selects a designated amount of characters in a string and stores them as a value in a new string. GM's syntax is the following:

Code: [Select]
var$ = mid$ var2$ characterToStartAt amountOfCharactersToSelect


So in the following example, var2$ would equal "BCD":

Code: [Select]
var1$ = "ABCDE"

var2$ = mid$ var1$ 2 3

« Last Edit: December 07, 2010, 01:13:48 PM by Silverwind »
I survived the spammage of 2007