The Daily Click ::. Forums ::. Klik Coding Help ::. Get element without stringparser
 

Post Reply  Post Oekaki 
 

Posted By Message

Jarzka



Registered
  26/12/2003
Points
  270

VIP Member
11th July, 2007 at 07:00:26 -

So I have n number of active objects an all of them has this string:

32|64|96|12|32| and so on with some numbers
all of them mean X positions

I would like that the object moves to the next X position by getting the next element. Is it possible without string parser? I can't use it because I have lost of active objects.

So for example:
At the start of the rame:
- Active: add delimeter to "|"

Every second:
- Active: Set X position to Val( listGetAt$( "Alterable String A", 1) )

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
11th July, 2007 at 07:43:36 -

I think the easiest way to do what you want is this:


* Every 01"-00
(Active) : Set X position to Val( Mid$( string$( "String" ), value( "Counter" ) * 4, 3 ) )
(Counter) : Add 1 to Counter


It doesn't use delimiters to tell where one substring ends and the next begins. Instead, it uses substrings of a fixed length (3 characters / 4 including delimiter). If you need to change the length to something else, just change where it says 3, and change where it says 4 to 1 higher (that's to take into account the "|" which you'll probably want to keep to make editing the text easier.

Like I said, this requires that all substrings are the same length, eg. 001|012|123|
This shouldn't be a problem, but if you need to set the text from within the game, you can use:


* whenever...
(String 2) : Set alterable string to Right$("000"+ string$(String)"), 3)


This just puts zeroes in front of the number if required.

If you *need* to use delimiters and this is no good, let me know. It is possible, and I have an example somewhere, but it's more complicated.

 
n/a

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
11th July, 2007 at 08:35:04 -

You'll be please to know String Parser CAN handle all objects at once.

If you look at the expressions in String Parser, it has these two:
- Set String, return ""
- Set String, return 0

These allow you to set the Source String from within an expression. Since the expression runs once for each object you select, it will perform its String Parsery goodness for all instances of your object.

So you could do this:

Start of Frame
-- Parser: Set Delimiter 0 to "|"

Every Second
-- Active: Set X position to 'set( "String Parser", Alterable String A( "Active" )) + val(listGetAt$( "String Parser", 5))'

This will set all actives to the X position of the 5th element in their array. It *should* be unique for each one.

If you wanted each instance to have a different element that it was looking at as well (so not all of them are looking at element 5. Perhaps one looks at element 2, the other 4, etc), then you would need to base the element on another alterable value.


Finally, remember that you can rename Alterable Strings and Values. So you can rename 'Alterable String A' to 'Array' or anything else.

 
191 / 9999 * 7 + 191 * 7

Jarzka



Registered
  26/12/2003
Points
  270

VIP Member
11th July, 2007 at 09:30:35 -

Hmm, maybe I can use String parsers anyway. I did not think that it should handle many objects.

Anyway, thank you all for your fast help.

 
n/a

Jarzka



Registered
  26/12/2003
Points
  270

VIP Member
11th July, 2007 at 17:37:36 -

Well I think there is one problem.

When Active1 Flag 1 is ON and I set the source string, it sets it from some active1 object, not from it which has flag 1 on :S
EDIT: Or I did something wrong...

Sketchy: If possible, delimiters would be very good without string parser.

Image Edited by the Author.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
12th July, 2007 at 11:21:02 -

Actually, I don't think my method would help you here. Sorry It uses fastloops, so it would be just as easy for you to fastloop through each object and use the string parser.

Having said that, there shouldn't be a problem with flags. What other conditions do you have in the "flag 1 is on" event?

Also, what was the problem with my first suggestion?

 
n/a

Jarzka



Registered
  26/12/2003
Points
  270

VIP Member
13th July, 2007 at 10:54:53 -

Well I can send you the example file that I am working. I don't really know where the bug could be.

Please contact me if you want to check it.

Image Edited by the Author.

 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
13th July, 2007 at 15:40:30 -

Sure i can take a look if you want to mail/upload it somewhere.

 
n/a

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
13th July, 2007 at 22:52:22 -

Sketchy briefly touched on this, but the best method to do this would be to use a fastloop and the string parser.

Basically you need three things.
* 32|64|96|12|32| saved as an alt string in the actives
* Alt Val A as an ID number
* Alt Val B as current position in the string

Start of frame, spread 0 in alt a of your active.
Then always run the loop "move" for the number of actives you have.

On loop "move"
& alt val of active = current loop index of "move"
then
Set Source String to Active's Alt String;
Active.x = Get element number (Alt val B) using string parser
Add 1 to Alt Val B of the active.

Instead of always running the loops "move" (as this would pretty much instantaneously move the actives to the end of their strings) you should just call the "move" loop whenever you want them to move, ie. every 1 second.

I hope this helps.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Jarzka



Registered
  26/12/2003
Points
  270

VIP Member
14th July, 2007 at 07:46:42 -

Well I found the bug and it works now

 
n/a
   

Post Reply



 



Advertisement

Worth A Click