Connecting different responses to a specific variable

snowyowl

New Member
Reaction score
0
Hello!

I'm making a trivia map right now, and since I'm kind of bad at triggering in the SC2 Editor I could use some help.

Essentially, what I want to do is for the game, at a given point, choose one predefined question from a list of possible questions where each question has four different alternatives attached to them.
I thought I could achieve something like that with a Function but I can't figure out the rest.

Also, a side question, what's a Record used for?

Thanks for any help!
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
(It looks like all the triggers I wrote are a littlemessed up since I just wrote them out of memory instead of copying them. Just imagine them all on the same level. The first row should be indentated just as all the other rows)

A record is usually known as a struct in most programming languages. It's like a bunch of variables gathered together. Say for example that you're a bank and you want to keep track of your customers. You want to save their first name, last name, id number and bank balance. You could then have a record/struct with each one of those as separate variables in it.

To create a record, create a new record(Ctrl+U) and create the variables you want to store inside it. You'll then have to create a new variable. Set the type to "- Record". If you have several records, you'll have to select the correct one in a dropdown menu below the type. You can also make it an array to save several versions of this thing(If you want multiple customers, you'd want to do this)

You can now fill this record by using the "Set variable" action and choosing your record variable as the variable. You'll get a new parameter called member where you can choose a variable inside the record to set.
This is what the customer example could look like if you did it in the SC2 editor.
Trigger:
  • Set Customer[0].First_Name = Bob
    • Set Customer[0].Last_Name = Builder
    • Set Customer[0].ID = 9823112
    • Set Customer[0].Balance = 500.0
    • Set Customer[1].First_Name = Jenny
    • Set Customer[1].Last_Name = Jackson
    • Set Customer[1].ID = 8977212
    • Set Customer[1].Balance = 0.1


Now this fits perfectly with your trivia question. I would suggest you store the trivia questions in a record. The record should need 6 variables. The question, the four alternatives and the answer. If you feel confident about all this, you could make the alternatives into an array inside the record to reduce it down to 3 variables. Then you could set it to look something like this:
Trigger:
  • Set Trivia[0].Question = "What is 3+5?"
    • Set Trivia[0].Alternative1 = "0"
    • Set Trivia[0].Alternative2 = "-2"
    • Set Trivia[0].Alternative3 = "8"
    • Set Trivia[0].Alternative4 = "10"
    • Set Trivia[0].Answer = "8"


Now to get a random question you can do something like this:
Trigger:
  • Set rand = (Random integer between 0 and X)
    • Text Message - Display the message Trivia[rand].Question for (All Players)

rand is a local integer variable and X is the index on your last question. So if you fill up the trivia record array with questions on index 0, 1, 2 and 3, X would be 3.

You can then use "Trivia[rand].*something* to get the info on that specific thing for that question.
 

snowyowl

New Member
Reaction score
0
Thanks for the quick reply, however, after setting up the record, I can't fill it with information using the Set Variable. Inside the Record, I'm unable to do anything besides creating variables, thus I cannot use the Action - Set Variable.
When I try using a different trigger to fill up the variables, the Set Variable action won't find my record nor the triggers inside it.

This is what my record looks like:
2z3ozna.png


As you can see, it doesn't quite look like the one you created.
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
Ah, I was unclear on a vital point. The record itself is just kind of a template. We need to store it in a "- Record" variable. In my reply, I called the variable Trivia.

I see you've done the same, but you put it inside the record. You can't have a variable contain a record which contains the variable. It's kind of like putting the box that contains your house, inside your house. That's also why it says "Unknown Record" in the "Questions" variable. It can't find a record because it only looks inside the record.

To fix this, delete the Questions record variable inside the record and recreate it outside the record as a global variable. You can't fill it with the Set Variable action inside the record. You'll have to use the Set Variable action inside a trigger(Probably with the event "Map initialization", which makes the trigger run when the map starts. This means you're records will be filled at the start of the game so that you can use them whenever you want).
 

snowyowl

New Member
Reaction score
0
Alright! That seem to do the trick. It currently looks like this:
20ff1w9.png


As there will be multiple questions, each with 4 alternatives, what do you think is the best way to organize the indexes? As of now, I was thinking of having all possible questions that can occur on the first level in Questions[0].Question[x] etc and the next level of questions as Questions[1].Question[x] and so on.

Furthermore, I've been toying a bit with the View Script command, and since there will be numerous questions to be filled in manually I'd probably saved a lot of time by simply typing them right into the script.
I saw that there was a function to export the script, however, I can't seem to find a way to import the script itself into the editor. I can make changes in the View Script window, it also lets me compile, but each time I close the window the changes are discarded.
How do I overwrite the triggers in the Trigger Editor with a script?
 

Siretu

Starcraft 2 Editor Moderator
Reaction score
293
I was thinking you would have all the variables inside the record be normal variables, not arrays. That way Questions[0] contains all the information about question 0. The question itself, the four alternatives and the answer.

The comment I made about making the alternatives into an array was meant as a way to keep all the alternatives in one variable. Something like this:
Trigger:
  • Actions
    • SetVariable(Questions[0].Question, "What's the production cost of a Drone?")
    • SetVariable(Questions[0].Alternatives[0], "25 minerals")
    • SetVariable(Questions[0].Alternatives[1], "50 minerals")
    • SetVariable(Questions[0].Alternatives[2], "25 minerals and 10 gas")
    • SetVariable(Questions[0].Alternatives[3], "75 minerals")
    • SetVariable(Questions[0].Answer, "50 minerals"


But if you want to have different questions for different levels, it's a different story. I would however do it like I just showed but make Questions a 2d array instead(by increasing the second size above 0 as well). It makes sense that your record represents one question and all its information.

(By the way, you can post your code in here by selecting the parts you want to post, right clicking and pressing copy as text(or ctrl+shift+c) and pasting it in your post with [noparse]
Trigger:
tags around it)

When it comes to custom script, there's two ways that I use. In triggers or outside triggers. You can either create a new custom script outside by right-clicking in the list and choosing New>New Custom Script(Ctrl+Alt+T). In there, you can write galaxy as you normally would.

You can also use the Custom Script action which allows you to write custom script at that place in the code. That allows you to easily mix GUI and custom script and it's what I do most of the time.
 

snowyowl

New Member
Reaction score
0
I guess if I'd used a 2d Questions Record then I wouldn't need the Question and Answer variable to be arrays right? Furthermore, do I have to have an Answers variable to detect the correct answer? I'm thinking about having booleans linked (somehow) to each Alternative string variable. But maybe that requires more code (and therefore space) than doing a stringcompare between the alternative selected and the answer?
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
I would like to refer you to Ayanami's Wc3 Jass tutorial on structs, although there may be a few things that are different (like the way it is coded) it is the same basic idea and it may shed some light on the records area. But i would ignore the coding and methods as those are the main parts that dont carry over into Sc2's trigger editor, unfortunately blizzard thinks methods are pointless and refuses to move on to real object oriented programming.
 

snowyowl

New Member
Reaction score
0
That's a bummer, I'm taking a reexam in Java in August so I'd hoped some SC2 coding would inspire me to learn it again ;)
Anyhow, I just realized that the editor won't allow me to paste something from a different application (TextEdit) into the custom coding field. Fun!
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
lmfao, isnt that wonderful? The editor is just making friends all day long, its as friendly as a nagging wife...

The fact that you took java once means you should understand what a class is, records are just classes that take no methods and cant have private members

for example:
Code:
class JavaClass
{
    public int SomeMethod ();
    public int SomeMemberVar;
}
 
->
 
record Sc2Record
{
    integer SomeMemberVar
}
 
Function Definition: [Sc2Record].Some Method //note this is outside of the class, but you can name it to have an interesting ui
 

snowyowl

New Member
Reaction score
0
Yes, Siretu kindly reminded me, I just had to understand how I were to use them and set them up in the SC2 editor.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top