Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Selection From a List?
BonesTheRabbit Offline
Member

Posts: 68
Threads: 20
Joined: Feb 2012
Reputation: 2
#1
Selection From a List?

I'm trying to think of how to code a selection from a list. Something like this, I suppose:

void somefunction()
{
    string variable = {
        [1] = "String option A",
        [2] = "String option B",
        [3] = "String option C",
        [4] = "String option D"
    }
    int r = RandInt(1,4);
    AddDebugMessage("Selection: " + variable[r], false);
}

Of course, that's not valid code. I'm just hoping someone understands what I mean, and can tell me how to achieve this with the HPL2 editor without using repeated if then checks. Any assistance is greatly appreciated.

P.S. I am a complete layman when it comes to coding.
(This post was last modified: 12-20-2014, 09:43 AM by BonesTheRabbit.)
12-20-2014, 09:41 AM
Find
7heDubz Offline
Posting Freak

Posts: 1,329
Threads: 40
Joined: Feb 2013
Reputation: 41
#2
RE: Selection From a List?

I know what you mean and that should work, never dictionaries though, why not just use a list and get a random integer between 0-biggest number?

12-20-2014, 03:21 PM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#3
RE: Selection From a List?

What you want is an array, it goes like this:

Let's say I want to choose a random enemy from a list. This is the code:

Spoiler below!

PHP Code: (Select All)
string[] Enemy = { "grunt""suitor""brute" };
int randomNum RandInt(0,2);

AddDebugMessageEnemy[randomNum], false ); 


Every time I run that code I get a diff string from the list.

12-20-2014, 03:34 PM
Find
BonesTheRabbit Offline
Member

Posts: 68
Threads: 20
Joined: Feb 2012
Reputation: 2
#4
RE: Selection From a List?

(12-20-2014, 03:34 PM)Daemian Wrote: What you want is an array, it goes like this:

Let's say I want to choose a random enemy from a list. This is the code:

Spoiler below!

PHP Code: (Select All)
string[] Enemy = { "grunt""suitor""brute" };
int randomNum RandInt(0,2);

AddDebugMessageEnemy[randomNum], false ); 


Every time I run that code I get a diff string from the list.

This is exactly what I was looking for. I had forgotten the appropriate term. Thanks very kindly.
(This post was last modified: 12-20-2014, 09:34 PM by BonesTheRabbit.)
12-20-2014, 09:26 PM
Find




Users browsing this thread: 1 Guest(s)