How do I get the computer to choose the highest number?
How do I get the computer to choose the highest number?
I want the computer to choose the highest number of a set of variables:
Tweek 34
Dogma 25
Snake 11
Fox 16
Obviously the highest number here is Tweek at 35, but how do I get the computer to choose that variable. I have some Idea, but it would take hundreds of lines of code. Im sure there's a simpler way...
Tweek 34
Dogma 25
Snake 11
Fox 16
Obviously the highest number here is Tweek at 35, but how do I get the computer to choose that variable. I have some Idea, but it would take hundreds of lines of code. Im sure there's a simpler way...
When a man fears for his reputation, he will temporarily humble himself.
-Rohan-
-Rohan-
This is theoretically speaking but I suppose you want the name of the highest variable saved in a string at the end.
PaCDK allows the usage of < and > which makes the whole issue rather easy. But you can only compare 2 variables at once, so you need a few lines.
Haven't tested the code though, no guarantee if it's working.
PaCDK allows the usage of < and > which makes the whole issue rather easy. But you can only compare 2 variables at once, so you need a few lines.
Code: Select all
if_num(Tweek;>[Dogma])
setstring(highest-one-of-tweek-and-dogma;Tweek)
if_num(Tweek;<[Dogma])
setstring(highest-one-of-tweek-and-dogma;Dogma)
if_num(Snake;>[Fox])
setstring(highest-one-of-snake-and-fox;Snake)
if_num(Snake;<[Fox])
setstring(highest-one-of-snake-and-fox;Fox)
if_string(highest-one-of-tweek-and-dogma;>[highest-one-of-snake-and-fox])
setstring(highest-of-it-all;[highest-one-of-tweek-and-dogma])
if_string(highest-one-of-tweek-and-dogma;<[highest-one-of-snake-and-fox])
setstring(highest-of-it-all;[highest-one-of-snake-and-fox])
Thanks
Well, thanks for including actual coding as an example, it'll help. That was my original method, but the real game has over 25 different variables, so I was hoping for a single line of code that could calculate the highest set. I’m guessing there isn't so I might just have to dedicate a couple of days to writing all that code. Haha.
A little simpler (and Copy&Paste friendlier) solution would be:
In the end, MaxNum contains the value of the largest variable and MaxName contains the name of that variable. It's still a little work, but you can copy the if_num... part with the curly braces once and only have to change the variable name. Unless PaC-DK gets support for arrays, I think this is the easiest way to do this.
Code: Select all
setnum(MaxNum,0)
if_num(MaxNum; <[Tweek])
{
setnum(MaxNum; [Tweek])
setstring(MaxName; Tweek)
}
if_num(MaxNum; <[Dogma])
{
setnum(MaxNum; [Dogma])
setstring(MaxName; Dogma)
}
if_num(MaxNum; <[Fox])
{
setnum(MaxNum; [Fox])
setstring(MaxName; Fox)
}
You left out "Snake" that makes it look way shorter indeed
I like your solution too. In mine, I compare 3 pairs, twice each time. In yours, you compare all four variables, each time with the previous one. I don't think that one of them is better than the other. You are just using shorter own variable names which is more efficient.
I like your solution too. In mine, I compare 3 pairs, twice each time. In yours, you compare all four variables, each time with the previous one. I don't think that one of them is better than the other. You are just using shorter own variable names which is more efficient.
It's not just the variable names. Think about the amount of work for 25 different variables. In my solution, it is mostly copy&paste. Use the same code snippet 25 times and just replace the variable name. In yours, you will have to introduce 12+6+3+1=22 additional variables and comparisons, each with their own name and make sure that you always compare the right ones with each other and don't forget any. That will get very complicated very quickly. And just think about what happens if you need to add or remove one of the variables.Baelavay wrote:You left out "Snake" that makes it look way shorter indeed
I like your solution too. In mine, I compare 3 pairs, twice each time. In yours, you compare all four variables, each time with the previous one. I don't think that one of them is better than the other. You are just using shorter own variable names which is more efficient.
@Schiman
Thanks, I didn't know that (or I forgot). That way you could even sort the whole list instead of just finding the topmost one.
I'm sorry, but I'm going to explain the array-thing in German ^^.
Was Arrays sind weißte ja, gehe ich mal von aus.
Im PaC-DK ist es möglich Variablen dynamisch zu erzeugen.
Du kannst einen Variablennamen bestehend aus anderen Variablen beliebig zusammenbasteln.
Beispiel:
Du würdest nun eine Variable besitzen, die den Namen "Array1" und den Wert "29" besitzt.
Du kannst damit perfekt mit Arrays und Schleifen arbeiten.
Nehmen wir an, du willst ein Array haben, wo die Werte von 0 bis 100 eingespeichert sind (also Wert == Index)
Du baust also eine function, die folgendemaßen aufgerufen wird:
Die function "nullbishundert" enthält nun folgenden Code:
Du hast also faktisch eine do-while-Schleife mit Endbedingung.
Nachdem die Function durchgelaufen ist, hast du folgende Variablentabelle:
Du hast also dynamisch 101 Variablen erstellt und damit eine Art 101-elementiges eindimensionales Array erstellt.
Mit mehreren Indizes sind multidimensionale Arrays auch kein Problem. Dabei muss man aber beachten, dass die einzelnen Indizes mit einem Platzhalter getrennt werden.
Ungefähr verstanden, was ich meine?
Dieses Konstrukt ist unabkömmlich, wenn du so Sachen wie den Stuboter oder mein Kampfsystem scripten willst ^^.
Das einzige Problem ist(und das sehe ich auch als großes Manko im PaC-DK), dass die Funktionen nur mit 50 Durchläufen pro Sekunde arbeiten. Das ist zu langsam. Aber das lässt sich nicht ändern. Man muss sich eben so behelfen, dass man den Code der Funktion einfach zweimal hintereinanderkopiert, dann hat man schon 100Hz ^^.
Was Arrays sind weißte ja, gehe ich mal von aus.
Im PaC-DK ist es möglich Variablen dynamisch zu erzeugen.
Du kannst einen Variablennamen bestehend aus anderen Variablen beliebig zusammenbasteln.
Beispiel:
Code: Select all
setstring(VarName;Array)
setnum(index;1)
setnum([VarName][index];29)
Du kannst damit perfekt mit Arrays und Schleifen arbeiten.
Nehmen wir an, du willst ein Array haben, wo die Werte von 0 bis 100 eingespeichert sind (also Wert == Index)
Du baust also eine function, die folgendemaßen aufgerufen wird:
Code: Select all
setnum(index;0)
function(nullbishundert;1)
Code: Select all
setnum(array[index];[index])
setnum(index;+1)
if_num(index;>100)
stopfunction(nullbishundert)
Nachdem die Function durchgelaufen ist, hast du folgende Variablentabelle:
Code: Select all
Name Wert
array0 0
array1 1
array2 2
.
.
.
array99 99
array100 100
Mit mehreren Indizes sind multidimensionale Arrays auch kein Problem. Dabei muss man aber beachten, dass die einzelnen Indizes mit einem Platzhalter getrennt werden.
Ungefähr verstanden, was ich meine?
Dieses Konstrukt ist unabkömmlich, wenn du so Sachen wie den Stuboter oder mein Kampfsystem scripten willst ^^.
Das einzige Problem ist(und das sehe ich auch als großes Manko im PaC-DK), dass die Funktionen nur mit 50 Durchläufen pro Sekunde arbeiten. Das ist zu langsam. Aber das lässt sich nicht ändern. Man muss sich eben so behelfen, dass man den Code der Funktion einfach zweimal hintereinanderkopiert, dann hat man schon 100Hz ^^.
Oh, kleiner Fehler^^.
Beim Aufruf der Funktion "nullbishundert" muss stehen:
Beim Aufruf der Funktion "nullbishundert" muss stehen:
Code: Select all
setnum(index;0)
function(nullbishundert;infinit)