Instance Variable Help

Get help using Construct 2

Post » Tue Aug 20, 2013 8:03 am

Hello, everyone I just wanted to see I could get some help with a problem.

I have enemies that are referencing an Instance Variable as to what their action should be. Example: Action: 1 = Punch, Action: 2 = Kick Etc.

however, currently actions are chosen at random, what I would rather is have a list 1,2,3,4,5 this way I can restrict actions for varied enemies like 2,2,2,1 this enemy will mostly kick but sometimes punch.

My problem is that when I create a variable to control what actions can be picked it must be a text format to allow for multiple numbers but I then can't set the numerical actions to pick as they clash.

I hope this makes sense other wise

I want Instance Variable Actions to be set to a number in Instance Variable Available_Actions, where Available_Actions = 1,2,3,4
Posts: 6
Reputation: 646

Post » Tue Aug 20, 2013 5:20 pm

Action is a number.
AvailableActions is text (e.g. "1,2,3,4").

Set Action to
[code]int(tokenat(AvailableActions, floor(random(tokencount(AvailableActions, ","))), ","))[/code]
example (r141)

int(tokenat(AvailableActions, floor(random(tokencount(AvailableActions, ","))), ","))
tells you how many values there are in AvailableActions separated by a comma (in this case 4)

int(tokenat(AvailableActions, floor(random(4)), ","))
give you a random number from 0 to 3 (e.g. 0)

int(tokenat(AvailableActions, 0, ","))
gives you the value in AvailableActions at position 0 (i.e. "1")

converts the text into a number, int("1") = 1
Posts: 1,520
Reputation: 25,650

Post » Thu Aug 29, 2013 4:02 am

Hey, thank you so much this works perfectly, my enemies are now unique with their actions. Thank you for explaining it so well I wouldn't of figured that out on my own.

If and when I release the game you'll be on the credits for this.
Posts: 6
Reputation: 646

Return to How do I....?

Who is online

Users browsing this forum: rayolf, Yahoo [Bot] and 10 guests