Forum Thread
  Posts  
Printing an associative array in CoD scripting (Forums : Coding & Scripting : Printing an associative array in CoD scripting) Post Reply
Thread Options
Jan 10 2017 Anchor

hey guys,

i'm new to these forums but have referred to the numerous posts and tutorials on CoD scripting on here from time to time. now i've come across something i haven't found on here yet.

how can i print the whole content of an associative array? for example, there's the array "game", which holds values like game["axis"], game["allies"], game["round"]. i'd like to know all the values it contains. i've tried this:

testfunc()
{
	wait 5; // this makes the game wait while the game is starting the home-hosted server
	iprintln("printing " +game.size+ " elements:");
	for(i = 0; i < game.size; i++)
	{
		iprintln(i +": " +game[i]);
	}
	iprintln("printed.");
}

it does print "printing 94 elements", but then it doesn't print the individual elements. that's cos you can only access associative arrays with their keys, not with indexes. how can i print all elements of this array?

thank you very much!

regards,

logithack

Nightshade
Nightshade Technical Artist
Jan 11 2017 Anchor

You are not printing the contents because you are refering to the associative array (aka "dictionary") content by index, when in fact the dictionary is made up of key/value -pairs.

Normally that is not how you access key/value -pairs. Now I don't know what language you use in CoD but the solution is probably something like:

for x in game{
    for y in game[x]{

// OR something like:
for k, v in game{
    iprintln(k);
        iprintln(v);

Does this make sense?

Edited by: Nightshade

--

Technical Artist @ King - an Activision-Blizzard studio
Portfolio | LinkedIn

Jan 12 2017 Anchor

that makes sense! the code is written in Quake C. unfortunately, however, it accepts neither of your solutions. the error displayed is "bad syntax".

i've been messing around with this:

testfunc()
{
	wait 5; // this makes the game wait while the game is starting the home-hosted server
	for(i = 0; i < game.size; i++)
	{
		key = game[i];
		iprintln(key +": "+ game[key]);
	}
}

however, it won't print anything. there must be some way of dumping the content of the dictionary. i've googled how to print the contents of associative arrays in C/C++ but that doesn't really help me in this case.

any help greatly appreciated! and thank you Nightshade for your hint!

regards,

logithack

Nightshade
Nightshade Technical Artist
Jan 12 2017 Anchor

It's bad syntax because it's pseudo code. I couldn't find any documentation on QuakeC so I can't help with the syntax.
But from the name and looks it appears to be just another language in the C-family. Now you do not have dictionaries in C (sure you can simulate them with hash tables but it's not the same) but for C# the syntax is like:

foreach (KeyValuePair item in myDictionary)
{
    MessageBox.Show(item.Key + "   " + item.Value);
    // The above would be iprintln(item.Key + ": " + item.Value); in your case. MessageBox is a C# class for making dialog windows (I think?)
}

But that's another language. Maybe QuakeC doesn't have a for-each -loop.

Either way... if you are trying to learn programming then I strongly recommend that you do NOT pick an old, niche language that has poor or no documentation. I understand that you are probably looking into modding some favorite game, but for the purpose of learning there are much easier roads for you to walk. Learning C# and making a game in Unity is going to be much, much easier for you. It's an excellent engine for rapid prototyping (less good for very big projects/teams) and the C# knowledge is very valuable. Additionally you have excellent documentation and a community full of professionals ready to be there and help you if you have problems.

Edited by: Nightshade

--

Technical Artist @ King - an Activision-Blizzard studio
Portfolio | LinkedIn

Jan 18 2017 Anchor

i have learnt how to code in different languages. i started out with programming a few years ago by looking into Quake C and adding stuff to the mod on our CoD2 server. you've called the problem by its right name, there's little to no documentation on Quake C. i have worked with associative arrays in different languages, so i'm familiar with that. however, i just couldn't get it to work in Quake C since i can't find any documentation on how to print the contents of an associative array.

anyway, i was just interested in the contents of that array. but it doesn't matter that much. if i happen to find a way of printing the contents of an associative array, i'll let you know. still thanks for your help!

regards,

logithack

Edit: and you were right, MessageBox is a C# class for making dialog windows and MessageBox.Show(<something>) would display <something> in it. however, the only means of printing output to the screen in CoD is using iprintln(), which prints something to the bottom-left corner of the screen, or iprintlnbold(), which prints something to the centre of the screen.

Sep 14 2017 Anchor

Hey Gusy, myself Alex. I want to share information regarding 3D printing, how actually its work. Getting started with 3D printing means asking yourself what you want to learn first. Are you want to know about hardware or end result making objects. This question make your decision about pre-assembled 3D printer or a 3D printer kit. 3D printing technology is destined to change all major industry and change the way we live, work and play in future. Applications include rapid prototyping, architectural scale models & maquettes, 3D printed prosthetics and movie props. If you want to know that, 3D printing is the right tool for you or not. You can check possibilities without purchasing a 3D printer via 3dinsider.com. Here you can find valuable information regarding printing.

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.