With 50+ images -one selected randomly?

Freeform discussion about anything related to modding Transcendence.
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

If I have a very large number of image variants (like 50, 100, 500 or more), do I still have to list each image variant location out separately under <image variants> or is there a way to fill in the X and Y coordinates with randomly generated numbers?

For instance, instead of this:

<ImageVariants>
<Image imageID="&rsRanStation;" imageX="0" imageY="0" imageWidth="128" imageHeight="128"/>
<Image imageID="&rsRanStation;" imageX="0" imageY="128" imageWidth="128" imageHeight="128"/>
<Image imageID="&rsRanStation;" imageX="0" imageY="256" imageWidth="128" imageHeight="128"/>
</ImageVariants>

...Is there a shortcut of some sort that would allow me to randomize the number for X or Y and do something like this (by the way, I know the example below does not work - after experimenting with this, I see it just defaults Y to 0 - but is there some other way to do this in the Code?)

<Image imageID="&rsRanStation;" imageX="0" imageY="1d3*128-128" imageWidth="128" imageHeight="128" />

Thanks!
User avatar
Cygnus.X1
Militia Lieutenant
Militia Lieutenant
Posts: 245
Joined: Sun Feb 24, 2008 6:21 pm
Location: Elysium Fields... I mean System
Contact:

marsrocks wrote:<Image imageID="&rsRanStation;" imageX="0" imageY="1d3*128-128" imageWidth="128" imageHeight="128" />
totally blind guess, depending on if the X/Ys accept variables, but...

(setq imgY (subtract (multiply (rollDice 1 3) 128) 128))

then

<Image imageID="&rsRanStation;" imageX="0" imageY=imgY imageWidth="128" imageHeight="128" />

"imageY=imgY" this is the part I'm not sure about...
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

Cygnus - thank you for that attempt!

I plugged it into my experiment - but unfortunately, it came back with the error:

attribute value must be quoted.

So, I then tried putting the variable in quotes:

imageY="imgY"

but it just defaulted the Y coordinate back to zero.
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

I also tried substituting your formula directly into the code - and it also just defaulted the Y coordinate back to zero in the test:


<Image imageID="&rsRanStation;" imageX="0" imageY="(setq imgY (subtract (multiply (rollDice 1 3) 128) 128))" imageWidth="128" imageHeight="128" />
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

Oops - ran it again like this - also defaulted Y to 0.

<Image imageID="&rsRanStation;" imageX="0" imageY="((subtract (multiply (rollDice 1 3) 128) 128))" imageWidth="128" imageHeight="128" />
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

also tried removing the beginning and ending parentheses with same result.
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

It looks like x and y won't accept variables. That leaves me with copy and paste, which is fine, I guess, unless anyone has any other ideas.
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

imageY="((subtract (multiply (rollDice 1 3) 128) 128))"
hi marsrock,
unfortunately very few fields can accept Tlisp code. One of these is name="xxxx" for example.

[also, moved topic to Shipyards as it's more about modding]
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

Thanks, digdug. How about a possible xml solution where the x and y are split off in subtags within the <image> or <imagevariants> tags?
User avatar
Cygnus.X1
Militia Lieutenant
Militia Lieutenant
Posts: 245
Joined: Sun Feb 24, 2008 6:21 pm
Location: Elysium Fields... I mean System
Contact:

the TLisp code part would have to be triggered somehow, typically through an intrinsic event like <OnCreate> or something similar. The game engine won't run code that's embedding into an XML tag's attributes.

And from your results, I'd say this isn't possible because the game engine doesn't seem to acknowledge vars being used as attribute values.

Might try asking in IRC ;)

(post-post) just saw digdug's reply, that confirms it
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

Thanks - I may try the IRC - (are there a lot of people there?)

I'm still at the very beginning stages of learning this (probably obvious - but thanks for not laughing), but I found these in the functions lists:

What would the code look like using these/ what do they do/ and could I use a variable in either of these to accomplish what I am trying to do?


(resCreateImageDesc imageUNID x y width height) -> imageDesc


(staSetImageVariant station variant)
User avatar
Cygnus.X1
Militia Lieutenant
Militia Lieutenant
Posts: 245
Joined: Sun Feb 24, 2008 6:21 pm
Location: Elysium Fields... I mean System
Contact:

Those kind of questions are best asked in IRC. :D

There are a fair number of regular users in the IRC chatroom, but like any chat room, don't freak out if you don't get a response immediately, international community and all that so we aren't all on the same day/night schedule, right?

Some of my biggest coding saves came from suggestions and corrections from peeps on IRC, especially StarWeaver ;)

And don't feel to bad about being new at all this, we were all 'new' at some point and nobody's going to laugh at you unless you say something really funny, at which point they might use the IRC bot to quote you for all time :mrgreen:
RPC
Fleet Admiral
Fleet Admiral
Posts: 2876
Joined: Thu Feb 03, 2011 5:21 am
Location: Hmm... I'm confused. Anybody have a starmap to the Core?

Tutorial List on the Wiki and Installing Mods
Get on Discord for mod help and general chat
Image
Image
Der Tod ist der zeitlose Frieden und das leben ist der Krieg
Wir müssen wissen — wir werden wissen!
I don't want any sort of copyright on my Transcendence mods. Feel free to take/modify whatever you want.
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

why don't you just use an <OnCreate> event to randomly apply an image variant for your station ?
something like this if you have 50 variants ?

Code: Select all

<OnCreate>
(staSetImageVariant station (random 0 49))
<OnCreate>
marsrocks
Commonwealth Pilot
Commonwealth Pilot
Posts: 55
Joined: Fri Nov 05, 2010 6:29 pm

digdug, the way I understand it, currently, we have to list each image variant line by line for stations, giving specific details of where each image variant is in your image resource. For 50 stations, you need 50 lines describing the locations; for 500 stations, you need 500 lines of code describing the specific locations of your image variants.

Once you produce that text, the game already automatically selects one of those image variants from your list at random for your station. If you don't describe the image variants, I don't think the game can select any random image oncreate or otherwise. So, using the random selection of a variant oncreate, would be redundant to what the code already does, and it doesn't really solve the problem of reducing the need to add all these lines of code to describe the many alternative image locations.

The idea of the proposed new code is to get the game to choose a station from a random location from your larger image (an image of a grid of stations), without the need for a detailed line by line description. In effect, with 50 stations, you currently need 50 lines of code within the imagevariants tags. With the ability to set a grid of some sort on your image from which the images could be selected, you can reduce that to just a few lines of code to give it all the information it needs to know the locations of your 50 different image variants- (even if it was 500 or more image variants, (set in a 4 x 125 grid, for instance), you would only need a few lines of code describing your grid, which makes it a lot easier to insert more image variety into the game).

For example, with imagevariants, you would have a line for each variant (this is just 3 lines in the example, which is easy enough, but imagine having to describe 500):

<ImageVariants>
<Image imageID="&rsRanStation;" imageX="0" imageY="0" imageWidth="128" imageHeight="128"/>
<Image imageID="&rsRanStation;" imageX="0" imageY="128" imageWidth="128" imageHeight="128"/>
<Image imageID="&rsRanStation;" imageX="0" imageY="256" imageWidth="128" imageHeight="128"/>
</ImageVariants>

What starweaver is proposing to add, would make it so it can be done by simply describing a grid where the variants are found. So, instead of 50 or 500 lines of code to tell it where your many variants are, you would only need to put your stations in a gridded image, and then use something like this:

<ImageVariantsGrid
imageID = "&rsSomeImage;"
imageHeight = "128"
imageWidth = "128"
imageCountX = "3"
imageCountY = "4"
/>

Starweaver's example shows a 3 X 4 matrix of 12 stations each having a size of 128X128 pixels.. The example below would describe 500 stations just as easily, each with a size of 32x32 pixels:

<ImageVariantsGrid
imageID = "&rsSomeImage;"
imageHeight = "32"
imageWidth = "32"
imageCountX = "125"
imageCountY = "4"
/>

(In the example above, we have successfully described 500 station image variants set out in a gridded image which is 32 pixels wide and 32 pixels high, on a 4 X 125 grid).

Later, perhaps, we can have the game select from a portion of the image variants with a random selection from within that group. For instance, if we wanted the game to only select from the first 100 variants of those 500 for a particular station, we would then use (staSetImageVariant station (random 1 100)); or if we wanted a particular station from the group to always appear in a certain instance, we could say: (staSetImageVariant station 38).

In the mod I am currently working on, I have already described 500 tiny station variants using the existing imagevariants code, but it would be much easier to do that if I could describe a grid instead in future versions or future mods using lots of image variants.
Post Reply