Inserting 'Random Function' in to table cell, to change attribute

Good morning, evening, night - wherever you are!

This is my first post, so Hi! :-D
Ive found many answers to my amateurish questions so far on here, as well as the many videos on YouTube etc - so thanks for all that.
There is however, a question that I cant seem to find an answer to - maybe due to using the word 'random' in the search string, it brings up additional results related to random numbers etc.

All Im looking to do, is the following:
I have an actor that I want to appear for a random amount of seconds, which is easily done, until I want to change this for each individual level to make the game more difficult. So of course I set up a table, and a new attribute 'StarSpawnTime'.
I entered 'random(1,4)' in the table cell (set as Text) and called this up from a change attribute rule within a RoundRules actor of that level.

When the game plays, it plays fine - until the actor is due to appear, and it then freezes/hangs.

Am I missing something simple? I bet I am! ;)

Thanks for reading, and in advance for any replies...

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598

    Hi @gizmokris and welcome to GSC and the forums. :smile:

    Couple of things: if you are simply wanting a random value from one attribute (in your case StarSpawnTime) thee's no need to use a Table at all. Also, even if you needed a table, the random value you're requiring is a number so setting the table type as Text wouldn't work (and is the probable cause of of the hanging/freezing).

    So in this case, forget the table; if you want this random value automatically at the beginning of each scene, make a game integer attribute called StarSpawnTime, put the following behaviour in a blank actor outside of the screen area for each scene:

    Change Attribute StarSpawntime to random(1,4)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gizmokrisgizmokris Member, PRO Posts: 35

    Thanks for the quick response and welcome @gyroscope! :-D

    I would like to change StarSpawnTime (and also 3 others that have a similar rule) for each level, I currently have 30 levels. Im due to Beta test soon to work out an ideal gameplay difficulty to spread across the 30 levels, therefore they will require a lot of changing.
    If they are all in one table, I can see them all at a glance and it will save me a lot of time when changing them - so for this instance I would like them set up that way, if its possible?

    I thought that 'text' wouldn't be the correct option for the column, but it wont allow me to enter 'random(1,4)' as an integer (obviously due to the text). I guess the main question is, how do get around that issue?

    Thanks, again ;)

  • colandercolander Member Posts: 1,610
    edited September 2014

    random() is a function which can only be used in the expression editor. A table in GS is not like Excel you can not run functions in them they only store values.

  • gizmokrisgizmokris Member, PRO Posts: 35

    Thats not the answer I was hoping for, but feared was coming! ;) haha! Thanks @‌colander

    So, a workaround would be to create another table, with a range of numbers (1 to 4, in this case) and to select a random cell from within that range?

    If that makes sense, I'll be impressed - I only started using Gamesalad a few weeks ago, and tables just yesterday...

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2014

    Hi again, as I said previously, there's no need for a Table to simply randomly change an attribute value; you do that using the random expression via the expression editor, as @colander pointed out.

    for the record, you could use the random expression to choose a random row value from a table as you're asking(providing its set to integer for what you're wanting), but in this case, this involves extra work when it can be done much more straightforwardly.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    @gizmokris said:
    Thats not the answer I was hoping for, but feared was coming! ;) haha! Thanks @‌colander

    So, a workaround would be to create another table, with a range of numbers (1 to 4, in this case) and to select a random cell from within that range?

    If that makes sense, I'll be impressed - I only started using Gamesalad a few weeks ago, and tables just yesterday...

    Yes. So if it's in a timer and the numbers are four rows in one column, it would be table cell value (yourtable,random(1,4),1)

  • gizmokrisgizmokris Member, PRO Posts: 35

    @gyroscope‌ - please let me know if Im missing something, but in order to change the value in the expression editor, I would need to go to each scene, then in to the actor and then change the random(1,4) value? For all 30 levels.

    • Sorry for the back and forth, but I like to make sure I fully understand, and If im missing a little trick, then Id rather know :-D

    @The_Gamesalad_Guru‌ - Awesome, thank you.
    For this to work automatically for each level, I would amend it to show the following:

    table cell value (yourtable,random(1,4),game.Level)

    (I have a game attribute set up that gives each level a number in order to unlock levels and add star values etc)

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Well if you kept the prototype intact you should just have to edit the actor in the actors pallet. If you didn't keep the prototype locked, as you should be doing, then yeah you got some work to do.

  • gizmokrisgizmokris Member, PRO Posts: 35

    Prototype is in a chastity belt and Ive thrown away the key... ha!

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2014

    @gizmokris said:
    gyroscope‌ - please let me know if Im missing something, but in order to change the value in the expression editor, I would need to go to each scene, then in to the actor and then change the random(1,4) value? For all 30 levels.

    • Sorry for the back and forth, but I like to make sure I fully understand, and If im missing a little trick, then Id rather know :-D

    A neat technique when making a game with lots of levels, especially if the elements are similar on each level, is to make your first level then go to Home> Scenes, hold down alt and drag to duplicate this master scene. Do this 30 times and you've got your separate scenes to adjust accordingly. But before this, make sure you've got

    Change Attribute StarSpawntime to random(1,4)

    in an actor outside of the first scene before duplication. This way, you've got it on every scene so it can randomly change your attribute straightaway when each scene is entered, as you want.

    For the record, personally I've no worries about unlocking actors if needed (or even if not needed) - as far as I'm concerned an unlocked actor has negligible or no effect on performance.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    It's not about performance as to unlocking actors it's about the time savings when one has tons of scenes. The only reason one would need to unlock an actor is if you need to access scene related attributes. If you know how to write integrated code most modifications can be done without ever unlocking a prototype by creating self attributes on an actor. My video on custom prototypes shows how effective it is.

  • gizmokrisgizmokris Member, PRO Posts: 35

    Thanks for the tips @gyroscope‌ , thats what I did to create my total amount of scenes.
    Would take a verrrry long time otherwise to build each one again ;)

    I understand about unlocking, but I might want to (meaning I most definitely will!), make changes again before the game - so keeping them locked for me is good practice.
    And like I said, having the timings for my 3 or 4 actors in one place to view and change quickly (within seconds, as opposed to potentially an hours work) - therefore a table is ideal.

    So, I came up with this work-around, it made my head hurt to work it out, and I'll be honest, when it worked first time, I was surprised and actually 'Woo-Hoo'd' out loud! haha

    • I created 2 tables: 'tblImageTimings' & 'tblSeconds'

    • In the first Ive got 2 rows for each image - 'Minimum Seconds' & 'Maximum Seconds'
      The columns in this are my levels

    • In the second, 58 rows (one for each second, my game lasts for 60 seconds)
      One column for the seconds.

    In my scene I have an off screen actor with the following:

    Change Attribute 'game.StarSpawnTime' to 'random(tableCellValue( game.tblSeconds , game.Level ,tableCellValue( game.tblImageTimings ,1, game.Level )),tableCellValue( game.tblImageTimings ,2, game.Level ))'

    Looking at it now, Im getting confused - but it took me a few minutes to work it out and eventually come to the solution.

    If anyone has any input to make that any simpler, please shout - or if that helps anyone else in the future - then great stuff! ;)

    Now to implement that for the other 3 actor attributes... eeeek! Pass me a coffee...

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited September 2014

    @gizmokris said:
    Thanks for the tips gyroscope‌ , thats what I did to create my total amount of scenes.
    Would take a verrrry long time otherwise to build each one again ;)

    I understand about unlocking, but I might want to (meaning I most definitely will!), make changes again before the game - so keeping them locked for me is good practice.

    sure, keeping a Prototype actor to amend all those actors from it in one go is good practice, agreed! I thought you were worrying about unlocking an actor with an impact on performance, etc... misunderstood there... :smile:

    A for using your tables for 4 actors needing random times, I still can't see why you consider making your tables is less work/easier than

    Change Attribute 1StarSpawntime to random(1,?)
    Change Attribute 2StarSpawntime to random(1,?)
    Change Attribute 3StarSpawntime to random(1,?)
    Change Attribute 4StarSpawntime to random(1,?)
    

    Possibly i've misunderstood what you're after again, but if not, there we are, if you're happier with your way, then fine! :smile:

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gizmokrisgizmokris Member, PRO Posts: 35

    @gyroscope‌ Really do appreciate your input! :)

    Maybe because what Ive explained is out of context from the complete game, therefore not giving the full picture.
    One of the other actors has 2 attributes that require changing for each level

    • PhotoSpawnAppear 'random(1,10)'
    • PhotoSpawnTime 'random(1,4)'

    The gameplay is based around a whack-a-mole type game to give it some context.
    The images/photos show and the player has to touch them before they disappear to gain a point. There are about 20 of these on each level. (but there are only 3 stars, so they show up only once within the game time and then destroyed).

    Well, I did speak too soon, and realised that I hadn't changed my actor to read the attribute I set up the random rule for. And surprise surprise, when I did, it didnt work and the game hung as star was due to appear. B****x. haha

    I'll go through it again, because in theory, it should work.. its probably (hopefully?!) just a simple mistake I made selecting a row or value... hmmmm....

    Thanks again! :-D

  • gizmokrisgizmokris Member, PRO Posts: 35

    Ooops, that coffee was needed - I realised that I hadnt changed the Game Attribute to an integer from Text how I set it initially...

    It then worked, kinda! The image flashes up for a split second. Further tweaks needed, but Im close... ;) haha

  • gizmokrisgizmokris Member, PRO Posts: 35

    I started, so I'll finish... ;)

    Maybe I had too much Coffee? - what was I thinking?... I over engineered that totally. Didnt need the additional table of 'Seconds'

    The solution is here:

    • One table to keep track of all the changes 'tblImageTimings'
    • 2 rows for each image - 'Minimum Seconds' & 'Maximum Seconds' The columns in this are my levels (additional rows for Min/Max of the other actors and their timings)

    In my scene I have an off screen actor with the following:

    • Change Attribute 'game.StarSpawnTime' to random(tableCellValue( game.tblImageTimings ,1, game.Level ),tableCellValue( game.tblImageTimings ,2, game.Level ))

    This now seems to be working perfectly... looks like I got carried away earlier, hey, it was 'fun' though... :-/ ha

    Thanks for all the input!

Sign In or Register to comment.