• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM (ds_maps) Incorrect type, expecting a number error

David Chen

Member
Hiya devs! I'm getting an error with a textbox engine I'm writing (with the help of Edrem's engine). I'm using tags to let the engine know that I want to change the sound effect for the text typing. Here is the code I'm using:

Code:
if (string_count("[snd:", tag)) {
        snd = string_copy(tag, 6, (diff - 6));
        tbsound = tb.mapsound[?snd];
}
So, basically, "snd" retrieves the exact string from after any instance of "[snd:", for example, "snd" would retrieve "test" from [snd:test] and store it. After storing it, I'm trying to get the mapped value for snd and retrieve it to use with the audio_play_sound function. So basically, tbsound should run "test" through the map I've created to store sounds and retrieve "snd_test", an audio resource that can be used because "test" is mapped to the resource "snd_test". Except when I do this, I get this error:

############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object obj_textbox:

ds_map_find_value argument 1 incorrect type (2) expecting a Number (YYGI32)
at gml_Script_tb_step (line 43) - tbsound = tb.mapsound[?snd];
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_tb_step (line 43)
called from - gml_Object_obj_textbox_StepNormalEvent_1 (line 2) - tb_step();
Why is this? This code works fine for other mapped things like in-built colours and custom fonts made through "font_add_sprite". Why is it that this only happens with audio? (it's the only thing I've mapped to an actual resource though, maybe that's why? If so, is there a workaround? The thing is, mapping a string to a font resource also works fine ...)

Here is a list of things I've mapped using custom mapping scripts. Basically what each one does is maps the string on the left and returns whatever's on the right. Everything BUT the audio works fine.

Code:
//Map colours
// defaults
tb_mapcolour("aqua", c_aqua);
tb_mapcolour("red", c_red);
tb_mapcolour("blue", c_blue);
tb_mapcolour("black", c_black);
tb_mapcolour("white", c_white);
tb_mapcolour("lime", c_lime);
tb_mapcolour("yellow", c_yellow);
tb_mapcolour("purple", c_purple);
tb_mapcolour("orange", c_orange);
tb_mapcolour("fuchsia", c_fuchsia);
tb_mapcolour("maroon", c_maroon);
tb_mapcolour("teal", c_teal);

//Map fonts
tb_mapfont("default", font_add_sprite(spr_font_default, ord("!"), true, 1));
tb_mapfont("bold", font_add_sprite(spr_font_bold, ord("!"), true, 1));
tb_mapfont("three", font_add_sprite(spr_font_three, ord("!"), true, 1));
tb_mapfont("threet", font_add_sprite(spr_font_threet, ord("!"), true, 1));

//Map sounds
tb_typesound(snd_test);
tb_mapsound("test", snd_test);
tb_mapsound("test2", snd_test2);

//Map speeds
tb_mapspeed("zoom", 4);
tb_mapspeed("fast", 1);
tb_mapspeed("medfast", .75);
tb_mapspeed("med", .5);
tb_mapspeed("slow", .25);
tb_mapspeed("vslow", .125);
tb_mapspeed("debug", .05);
 
Last edited:
P

ParodyKnaveBob

Guest
Howdy, Mr. David,

I'm no expert, but a ds_map not calling up a resource value from a string key sounds pretty foreign to me. I threw a few search terms into the bug tracker and came up empty-handed there, too. For that matter, I wanted to confirm the argument type is a string, but that error's exact wording isn't in my copy of the manual. (@Nocturne?) Are you using Early Access? (I haven't reinstalled it since I changed computers, unfortunately.) Outside of re-creating your set-up, my main suggestion is to run a bunch of sanity checks outside the context of your system, then slowly integrate it back in.

E.g., can you simply (in the tb object)...
Code:
ds_map_create(mapsound);
mapsound[? "test"] = snd_test;
// show debug message(s) for ds_map_exists() on the key, is_real() on the value, sound_get_name() on the value, etc.
...then gradually add in the snd variable, whatever necessary script calls, instance scopes, etc.?

I hope this helps,
Bob
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
The error is saying that tb.mapsound itself is not a ds_map index, but a string. I would suggest to check that you are not accidentally overwriting it anywhere.
 
P

Paradox

Guest
I'm having the same problem and from what I'm aware I have put the "?" accessor everywhere its required...
 
Top