Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Question about game coding [Actionscript]

New Here ,
Jun 20, 2016 Jun 20, 2016

Hello Actionscript 3 Wizards,

I am looking to make a game in Adobe Animate CC. I have most of the Art assets drawn. I am looking for help with the code to do the following:

An object needs to be called at random from the library. The object ideally has a “Key” that corresponds to either Right or Wrong, True or False. Essentially the picture is a question that can be right or wrong based on if they choose Button A or Button B.

For Example, if they choose Button A, and it’s correct, I would like the score to update 2 points, and for the script to call the next object and start the process again.

Vice Versa, if it’s incorrect, the score is deducted and the process again repeats with a new object and possibility of it being right or wrong.

I apologize for my English, and thank you for any help I can get.

Please see the attached for a visual.

http://prntscr.com/bivdn4

TOPICS
ActionScript
502
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2016 Jun 21, 2016

your library objects each need a class name.  if those are chosen wisely, you can save some coding time.

eg, if you have Q1,Q2,.. classes, you can use the following to randomize question presentation and get started on your coding:

var C:Class;

var i:int;

var n:int = number of questions

var qIndex:int = 0;  // question index

var q_mc:MovieClip;  // assuming your questions are movieclips

var qA:Array = [];

for(i=0;i<n;i++){

qA.push(i);

}

shuffle(qA);

function nextQuestionF():void{

C=Class(getDefinitionByName('Q'+qA[qIndex]);

q_mc=new C();

q_mc.index = qA[qIndex];  // use this to retrieve info about the question

// probably you'll want to add to display here

}

function shuffle(a:Array) {

    var p:int;

    var t:*;

    var ivar:int;

    for (ivar = a.length-1; ivar>=0; ivar--) {

        p=Math.floor((ivar+1)*Math.random());

        t = a[ivar];

        a[ivar] = a

;

        a

= t;

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 21, 2016 Jun 21, 2016

That's amazing and super helpful. Thank you!

Why do the questions have to be classes? Why can't I just use the instance names to call upon them?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 21, 2016 Jun 21, 2016

if they're in your library like you mentioned, you have to use classes to create instances.

if they're already on-stage, they're already instances and classes aren't needed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 21, 2016 Jun 21, 2016

Thank you sir you helped a ton.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 22, 2016 Jun 22, 2016
LATEST

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines