Author Topic: Concatenate  (Read 3512 times)

0 Members and 1 Guest are viewing this topic.

Offline Cloudee1

Concatenate
« on: September 18, 2010, 12:35:20 AM »
I think I spelled it right. Anyway, I am trying to get a for loop going to try and lighten up that inventory script I wrote. If there is any way to concatenate a variable name. Basicly I want to create the inventory1, 2, 3... init() statements and it would be super nice if the number that would be added on, the 1, 2, 3 corresponded to i.


Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: Concatenate
« Reply #1 on: September 18, 2010, 08:50:18 AM »
I don't think so.  However, if you might be able to use an array - if you put your inventory objects into one.  I've had success creating props 'on the fly' like .
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: Concatenate
« Reply #2 on: September 18, 2010, 11:47:14 AM »
You  wouldn't  need  an array to draw views, no matter their type, on screen on the fly. Just use the one line init(), you don't even need instances.
Code: [Select]
(send (View:new()):view(211)loop(1)cel(0)posn(160 30)setPri(1)ignoreActors()addToPic()) If only on screen was all I was trying to accomplish, especially since the only thing that would need to be done to that line is change the cel number and it would be the same as i.

The problem comes with creating the pnc interaction after that. i need a name to check if you clicked on it and all I have is the item number. I wonder though, I wonder if I set the inventory items said property to a string, such as item1... if I could inject that variable name into my init line.
Code: [Select]
(if(send gEgo: has(i))...well crap I don't even know how to call up a particular items info probably a send though, maybe something like (send iItem: but that just tells it the iItem class, maybe the instanes name, (send {gruel}:Said()) hmm, maybe. but that doesn't help me all I've got is a number.

I'll bet I could stick my instance names in a text resource. But how do I get the line out of the text resource... I wonder if this would work?
Code: [Select]
Format(@txtstring 500 1)// where 1 is actually i
(@txtstring:init()posn(newX newY))
« Last Edit: September 18, 2010, 12:07:06 PM by Cloudee1 »
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: Concatenate
« Reply #3 on: September 18, 2010, 12:57:45 PM »
Ah, I never thought about using the ordinal corresponding to the view.  I guess I used an array because I wanted to keep other properties of the object with the object name as well.  I may have to revisit this.

Anyway - this will get you a string from a text resource & shove it into a variable (straight out of the sci studio help files) - looks just like the syntax you've got on the Format command.

Code: [Select]
(var aString[40])
GetFarText(100 5 @aString)

I also at one point considered putting object names into a text resource, but eventually went a different direction.

Again, using arrays would probably work.  You could have multiple arrays where one could be for your objects and the other could track the state of it (assuming the arrays were 'correlated' - the indexes would match up - you could just use the item # for the array indexes).  I haven't developed enough to fully grasp what you are attempting however, so take this with a grain of salt...

In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Cloudee1

Re: Concatenate
« Reply #4 on: September 18, 2010, 01:10:52 PM »
If you look here, you will see a big ugly script. I would like to trim it down some.

I want a for loop to take care of this, instead of manually adding it over and over again.

Code: [Select]
(if(send gEgo:has(3))
(inventory3:setPri(15)init()) // thumbnail view
    (if(>= newItemX maxItemX)
    += newItemY spacerItemY
    = newItemX firstItemX
    )
(inventory3: x (newItemX) y (newItemY))   
+= newItemX spacerItemX
)
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline gumby

Re: Concatenate
« Reply #5 on: September 18, 2010, 02:10:24 PM »
Okaaaaay.  That's a hell of a script.  This is perfect though - I need this solution for my own needs as well.  Like I referred to, I've got a solution for initializing views in a room script that utilizes a for loop.  I don't see why it couldn't be used for initing the inventory - this is what I'm starting from:

Code: [Select]
        /* Initialize all props in the room */
       
   (for (=  i 0) (< i 112) (++i)
              (if (== gRoomNumber gPropOwner[i])
  (send (= tempProp Prop:new()):view(800)
   y(100)
   x(100)
   init())
  = roomProps[i] tempProp
   )
 
   )

Basically, I've got a global array of all the object locations (gPropOwner) - I keep track of the object location here.  So on init of my room, I run through the array, initing everything that matches the current room.

So instead of having those case statements, you should be able to do something like this.  Could also throw the 'dropAble' code into an array as well.  So how about something like this:

Code: [Select]
           // Iterate through all objects
   (for (=  i 0) (< i 112) (++i)

              // Check to see if the ego has the object 'yes/no' array (0/1)
              (if (== 1 gEgoHasItem[i])

                           (if(>= newItemX maxItemX)
                               += newItemY spacerItemY
                               = newItemX firstItemX
                           )
                            += newItemX spacerItemX
                       
                           // Init the prop - put a reference to it into tempInv var
                           (send (= tempInv Prop:new()):view(i)
                                            y(newItemY)
                                            x(newItemX)
                                            init())
                           )
 
                          // Shove the tempInv into an array so we can use it later
                           = inventoryProps[i] tempInv
              )
   )


Is something like this what you are needing - or am I way off?  Not sure if you needed the 'Prop' initialized or if it's some other object.  But the premise is the same, I think. 
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.04 seconds with 22 queries.