Game Maker's Garage Forum

Game Creation => SilverCreator => Topic started by: Connors on December 05, 2011, 06:34:14 PM

Title: Strings Strings and more Strings
Post by: Connors on December 05, 2011, 06:34:14 PM
This happens every time and I'm sure this has come up before BUT how do I change a square of the map$ array?
FOR EXAMPLE:
map$(1) = "1,1,1,0,P,0,1,1,1,1"
I want to make the "P" a "0". Is it REPLACE$ or is that a different purpose?
Title: Re: Strings Strings and more Strings
Post by: Gan on December 05, 2011, 07:34:29 PM
Mmmm look in the Sc forum. I remember Redd making a function just for this using some NTHFields.
Title: Re: Strings Strings and more Strings
Post by: Circuit on December 05, 2011, 10:49:16 PM
I'm sorry I can't help.  I just wanted to ask a question.  Why are you using a string as an array instead of using a real array?
Title: Re: Strings Strings and more Strings
Post by: Gan on December 05, 2011, 10:58:41 PM
He's using both. He's making a double array and Sc doesn't support double arrays so he's forced to use a real with a fake inside.
Title: Re: Strings Strings and more Strings
Post by: Al Staffieri on December 06, 2011, 09:08:18 AM
SC doesn't seem to have much of the help done for the commands syntax. I was trying to do it with REPLACE but I don't know the right way to use it. There doesn't seem to be a LEFT$, RIGHT$, or MID$ either.

EDIT: OK there is a MID$ and you can use that in place of LEFT$ and RIGHT$ as well.
Title: Re: Strings Strings and more Strings
Post by: Al Staffieri on December 06, 2011, 09:30:36 AM
Looks like there's a lot of the command help in SC 1.5, Someone should try transferring it over or make a text file of it and include it with SC 1.6.

Here's how to do it:

LET map$(1) = "1,1,1,0,P,0,1,1,1,1"
' make a new string using chars 1 to 8 of map$(1)
LET change$ = MID$(map$(1),1,8)
'add on a 0 and then use 10th char onward from original map$(1)
LET change$ = change$ + "0" + MID$(map$(1),10)
' now set map$(1) to the new string you made
LET map$(1) = change$

Title: Re: Strings Strings and more Strings
Post by: Connors on December 06, 2011, 03:12:48 PM
Thanks for the help! I should try to just make a method for this, and save it as a file.
Title: Re: Strings Strings and more Strings
Post by: GMG Kurt on December 06, 2011, 06:20:12 PM
I hate that about SC. I always wanted to learn it, but was deterred by the lack of documentation.
Title: Re: Strings Strings and more Strings
Post by: Gan on December 06, 2011, 06:38:35 PM
All the docs are in 1.5.
Title: Re: Strings Strings and more Strings
Post by: Connors on December 06, 2011, 10:38:43 PM
I'll post a method to replace a part of a string$ soon.
Title: Re: Strings Strings and more Strings
Post by: Connors on December 08, 2011, 12:34:20 AM
I DID IT. I can replace a field, i can move around on the board... Now I just need to program in goals and moving boxes! Which just means I have to make another section of code for ALL FOUR DIRECTIONS. I think I'm gonna make a method for handlemovement. But I will post the current project shortly! :D ;D

EDIT: That was easy. Thanks MF.
http://www.mediafire.com/?av7f7t0tv38e6ax
Title: Re: Strings Strings and more Strings
Post by: Gan on December 08, 2011, 08:10:44 AM
Looks pretty sweet. Possible bug, when there is a block to your right, you hit the right arrow, then you hit the up arrow you can cut across diagonally.
Title: Re: Strings Strings and more Strings
Post by: Connors on December 08, 2011, 09:10:15 AM
That is weird... I think it's because it executes code for both arrows if you hold them down. I need to use IF ELSE for the keys.
Title: Re: Strings Strings and more Strings
Post by: Connors on December 13, 2011, 11:11:02 PM
Quote
That is weird... I think it's because it executes code for both arrows if you hold them down. I need to use IF ELSE for the keys.
Never mind, it just worked one way, and it's not a big problem right now since you can't really go through diagonals.
EDIT: I accidentally fixed it! You can't move twice really fast appearing to go across the diagonal anymore. XD

While we're talking about SC can conditionals in IF statements use AND or OR? I really would like this. I'm not sure how to do it. I have to make it push boxes onto floors OR goals and I want to walk across either of these. If I can't say OR it will require TWO COPIES OF THE SAME CODE. Thanks again!
Title: Re: Strings Strings and more Strings
Post by: Gan on December 13, 2011, 11:29:36 PM
I actually don't know if Sc supports this...
Make a temporary int, set it to 0.
If floor set temp int to 1
If goal set temp int to 1
If temp int is 1 then run move code

That's a little work around I suppose.
Title: Re: Strings Strings and more Strings
Post by: Connors on December 14, 2011, 02:19:42 PM
Yeah that's true. I can work that in. Also, I'm gonna dig up that old thread where we talked about DRAWIMAGE or whatever the function is and how it works without adding a sprite... It would be more like using the canvas. I think I'm more ready to try it out.
EDIT: I remember: The goal had been to somehow make sure the program can get images out of the folder they were installed in, because DRAWIMAGE requires a file path. But it could possibly lag if it has to open the file each time.
EDIT #2: I used the example code where the user finds a file, and had it print the string with the location. It looks like this:
Macintosh HD:Users:mcharneys:Desktop:image.gif
So the standard ~/Desktop/Image.gif will not work.
Title: Re: Strings Strings and more Strings
Post by: Gan on December 14, 2011, 02:48:25 PM
Yeah. Sc needs a way to store images and then draw stored images by calling it's ID.
On load:
LoadImage("/myImages/ball.png", "ball")
On draw:
DrawImage("ball",x,y)

Mike's been too busy lately to add new features. :/
Title: Re: Strings Strings and more Strings
Post by: Connors on December 14, 2011, 02:55:05 PM
Oh you posted while I was typing something. [smiley=cheesy.gif]
It would be great if LoadImage could start from the folder the game was in though!
OR just add one that uses the imported sprites. That would be amazing.
Title: Re: Strings Strings and more Strings
Post by: Gan on December 14, 2011, 03:01:51 PM
Indeed, being able to use imported sprites would solve the problem.
Title: Re: Strings Strings and more Strings
Post by: Circuit on December 14, 2011, 03:20:46 PM
That looks cool.  I remember playing a game like this on OS 7.

Quote
While we're talking about SC can conditionals in IF statements use AND or OR? I really would like this. I'm not sure how to do it. I have to make it push boxes onto floors OR goals and I want to walk across either of these. If I can't say OR it will require TWO COPIES OF THE SAME CODE. Thanks again!
SC can't do AND or OR, but you can create the same effects using nested IFs.  An OR would be like this:
Code: [Select]
IF (something is true) THEN
  //do stuff
ELSE
  IF (something else is true) THEN
    //do stuff
  END IF
END IF
Put the "do stuff" code in a method, and call the method each time.
Title: Re: Strings Strings and more Strings
Post by: Connors on December 14, 2011, 03:26:34 PM
thing is //do stuff will be the same. I suppose i should just use a method. But there's always more than one way with programming!
Title: Re: Strings Strings and more Strings
Post by: GMG Kurt on December 15, 2011, 09:06:37 PM
It'd be there for the whole running of the program so I suggest one variable flag you use in those situations over and over again
Title: Re: Strings Strings and more Strings
Post by: Al Staffieri on December 17, 2011, 08:30:27 AM
Quote
thing is //do stuff will be the same. I suppose i should just use a method. But there's always more than one way with programming!


You can do it this way


dostuff = 0
IF (something is true) THEN dostuff = 1
IF (something else is true) THEN dostuff = 1
IF dostuff = 1 THEN
 // do stuff here
END IF
Title: Re: Strings Strings and more Strings
Post by: EqwanoX on December 17, 2011, 09:35:12 AM
what are you all talking about? why would you use drawimage when you have sprite sheets?

why would you use nested IFs when you can use select case

Quote
This happens every time and I'm sure this has come up before BUT how do I change a square of the map$ array?
FOR EXAMPLE:
map$(1) = "1,1,1,0,P,0,1,1,1,1"
I want to make the "P" a "0". Is it REPLACE$ or is that a different purpose?
assuming your useing movex variables to track the player position you can do it in one line

let map$(1)=mid$(map$(1),1,moveX-1)+"0"+mid$(map$(1),moveX+1,len(map$(1)-moveX)

basically use mid$ command to take all the digits before and after the postition thats being editied
Title: Re: Strings Strings and more Strings
Post by: Connors on December 17, 2011, 09:43:57 PM
I got most of this worked out already, I'll post when it does more than just walk around a room. ;)
...But right now I have no Mac 'cause I'm on a road trip.