Table high Score searching a whole the column
scottharrrules43
Tulsa, OklahomaMember, PRO Posts: 694
i watched this video http://img.youtube.com/vi/RQtqPCDadt0/0.jpg
Wondering how to Search a whole row for the max?
Comments
From the screenshot above, it's clear that the tutorial is showing how to take the highest value of several columns using the max() function. If you were to do max(1,5,12,8) it would return 12 because it's the highest number. Because the tableCellValue() function returns the value stored in a table cell, you can think of each number in that example I just gave as being retrieved using tableCellValue(). So you might have something like this instead: max(tableCellValue(game.leaderboards,1,1),tableCellValue(game.leaderboards,1,2),tableCellValue(game.leaderboards,1,3),tableCellValue(game.leaderboards,1,4)). Assuming your table looked like this:
1 5 12 8
Then it would also return 12 since it's the highest value among all of those table cell values (aka columns). That would be the way to find the highest value of cells in a single row.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
What if the column changes 1 row to let's say 100 row is there a way to make it flexible change based on the number of rows?
I imagine you could build an expression using the table search functions to do the same thing. For on if you incorporate the row count function that will always give you the last row.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
what you enter for key (if you want to do this)?
Are you asking about how to take the maximum value for 100 rows? (I thought you were comparing values in columns but we it's a similar process either way). You'd need a loop to do that. See @Armelline's Bubble Sort demo for an example of that: http://forums.gamesalad.com/discussion/70000/armellines-free-stuff-for-everyone-check-first-post-for-the-latest-update/p1.
If you just need the index value of the last row/column, you can use the tableRowCount() or tableColCount() functions.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Scott I would recommend GShelpers video series on table functions. Seems to need to understand tables and their functions better.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
How would use tablerowcount() with the max() api? I am trying to make a online leaderboard that can be infinite maximum of rows?
Think about it for a minute... Variables are numbers and since table cells are stored static variables they're the same thing in theory. So a tablerowcount function is a call to the variable "last row in the table" whatever number that is. So you would use it like any other number or variable
Max(tablerowcount)
Have you ever watched my GSLogic series? I think you would benefit from it.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
I will have to watch that. But when i type Max(tablerowcount(leaderboard.game)) does not find the max value in a particular column it just displays the row count.
The max() function returns the highest value of any arguments. So if you do max(3,4), it will result in 4. If you make a tableRowCount() function an argument, as @The_Gamesalad_Guru said, that function will return an integer (e.g. 12 rows) and the max function will still return the highest value. So if you do max(3,tableRowCount(game.leaderboard)) using that same example, it will result in 12. It's not going to loop through the rows or columns of a table to find the highest value. It's just not what max() does. It would be like saying "I want the round() function to check all of my table cell values and round them each to a whole number." But round() takes numerical values as arguments and returns a single integer. You can't input a table or a row or a column into round(). Likewise, you can't do that with max(). It is expecting individual numerical values.
It seems like you don't have much of a programming background which can make it difficult to understand how functions work. Having knowledge of math functions in general is also helpful but programming logic is its own thing.
There is no built-in function to find the highest value among a series of table columns or rows. So you'll have to figure out how to do it. It might seem like we're withholding information but actually it's just a complex thing you're asking about. If you look at @Armelline's demo, you'll see how much work went into it. This isn't a question of which attribute to put where or even which function to use. Ultimately, the solution depends on how many columns (or rows) you have. If you have five, the best solution is to use max() and add every single cell value as arguments. If you have 100 or anything larger than about ten, it's going to be much more efficient to use a sorting algorithm such as a bubble sort.
And now that I think about it, if you don't actually need a sorted list but just the highest value, you could use a Loop over Table behavior to check each cell against a max value. So you'd loop through the row (or column) and if that value is greater than game.Max, you'd change game.Max to the table cell value. At the end of the loop process, game.Max would hold the highest value.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I agree doing a loop over table is the easiest way. This is complex function building, which is why I reccomended more study. I know you just want to do something now but learning is important to becoming a power user with game salad. We're always busy building some game so interviewing learning new stuff with your current work is always the best option. You can't keep putting it off or you'll just know how to copy and paste code and never learn how to write your own logic.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
@The_Gamesalad_Guru and @tatiang i am great with gamesalad except with tables. But thanks for all your help. Maybe when i get some time i will watch some video about table but i have some hard classes this quarter hard to take more time to learn.
If you plan on doing multiplayer in the future tables is must so it will be good prep for that.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS