GameMaker Studio 2; Weapon System. Error: DoConv :1: illegal undefined/null use; how to fix it? - var

Im trying to implement a weapon switching system in GameMaker Studio 2 and I'm following a tutorial to do so since I'm not too experienced with GML.
When I'm trying to run this script I'm getting the following error, and I can't find a way to get it to work.
############################################################################################
ERROR in
action number 1
of Create Event
for object :
DoConv :1: illegal undefined/null use
at gml_GlobalScript_ChangeWeapon (line 2) - var wp_map = weapons[weapon];
############################################################################################
gml_GlobalScript_ChangeWeapon (line 2)
And the script is:
weapon = argument0;
var wp_map = weapons[weapon];
sprite = wp_map[? "sprite"];
recoil = wp_map[? "recoil"];
recoil_push = wp_map[? "recoil_push"];
damage = wp_map[? "damage"];
projectile = wp_map[? "projectile"];
startup = wp_map[? "startup"];
bulletspeed = wp_map[? "bulletspeed"];
length = wp_map[? "length"];
cooldown = wp_map[? "cooldown"];
automatic = wp_map[? "automatic"];

This error may mean a few things:
You did not wrap the contents of the script in function <name>() { ... } (as per the message that you get when you create new scripts in 2.3), causing your code to be executed on game start (and, surely enough, without arguments)
You called your script without an argument (ChangeWeapon() vs ChangeWeapon(arg)).
You called your script with an argument, but argument's value is undefined.
Based on the error message, I would assume this to be the first of three.

Related

Invalid get index 'global' (on base: 'KinematicBody2D ('player.gd'))

I'm trying to make the enemy bullet follow the player, but the error: invalid get index 'global' (on base: 'Kinematicbody2D ('player.gd')) always pops up. When I looked this up, I found some problems similar to mine. The solution says to check the reference, but when I checked the reference, it looked right.
func atirar():
var dog = tirim.instance()
get_tree().get_root().add_child(dog)
dog.global_position = global_position
dog.add_to_group("delete_on_restart")
dog.dir = (get_tree().get_nodes_in_group("player")[0].global.position - global_position).normalized()
func _ready():
add_to_group("player")
dog.dir = (get_tree().get_nodes_in_group("player")[0].global.position - global_position).normalized()
it's a typo, it should be global_position
dog.dir = (get_tree().get_nodes_in_group("player")[0].global_position - global_position).normalized()

Java Application taking long time to execute Groovy scripts which are precomplied

I have my groovy script precomplied on server start (I have stored groovy scripts as varchar in DB) up like below in Map ,
final Binding sharedData = new Binding();
final GroovyShell shell = new GroovyShell(sharedData);
script= shell.parse(rs.getString("VALIDATION_SCRIPT"));
Now when checking the validation on input records based on specified validation id i try to execute the precompiled script as below.
Script scrpt = Validation.getScript(); //getting from cache
scrpt.getBinding().setVariable("attributes", objects);
scrpt.getBinding().setVariable("tools", scrpt);
GroovyResponse gr = scrpt.evaluate("tools.valid(attributes)");
but here my application takes long time to evaluate..i guess heap size also gets increase and GC takes place. Can any one help me if there are better way to do it. with out impacting the performance.
one of My groovy script :
import com.fis.derivatives.utility.generic.model.GroovyResponse;
def valid(Map mapInput){
GroovyResponse obj = new GroovyResponse()
if(mapInput.inputVal.equals("1")){
obj.setStatus(true) ;
obj.setResultValue("B") ;
} else if(mapInput.inputVal.equals("2")){
obj.setStatus(true) ;
obj.setResultValue("S") ;
}else{
obj.setStatus(false);
obj.setComment("Error : Unable to extract BUY_SELL. Please check BS value "+mapInput.inputVal+".")
}
return obj;
}
1 - I have doubts about your cache. getting from cache without any key is strange...
Script scrpt = Validation.getScript(); //getting from cache
2 - rework a little the call of groovy:
Script scrpt = Validation.getScript(); //getting from cache
//we will pass attributes as a parameter to method
//scrpt.getBinding().setVariable("attributes", objects);
//not necessary to pass to script link to itself
//scrpt.getBinding().setVariable("tools", scrpt);
GroovyResponse gr = scrpt.invokeMethod​("valid", objects);

Sprite object is not iterable, Platform Game (Python)

I am creating a platform game. I was trying to do a platform that went constantly up and down like an elevator, when i got this error: TypeError: 'Sprite' object is not iterable.
Here's the code related to the elevator:
IN SET UP:
self.platform_list = arcade.SpriteList()
self.elevator = arcade.Sprite()
for i in range(600,800,32):
self.elevator =
arcade.Sprite("imagenes/platformer/Ground/dirt_grass.png", SCALE_PLATFORMS)
self.elevator.center_x = i
self.elevator.center_y = 420
self.elevator.change_y = 2
self.platform_list.append(self.elevator)
IN UPDATE:
self.platform_list.update()
for plat in self.elevator :
if plat.center_y > 680 :
plat.change_y = - 2
if plat.center_y < 400 :
plat.change_y = 2
if i change the update by replacing plat for self.elevator, and get rid of the for, only one block of the ones that conform the platform goes up and down, the rest goes up without stoping, and gets out of the screen. I have tried also changing the for by "for self.elevator in self.platform_list" and then changing plat for self.elevator, but when i execute it, all platforms move up and down.
¿How can i fix this? Please help me.

GML room_goto() Error, Expecting Number

I'm trying to make a game that chooses a room from a pool of rooms using GML, but I get the following error:
FATAL ERROR in action number 3 of Create Event for object obj_control:
room_goto argument 1 incorrect type (5) expecting a Number (YYGI32)
at gml_Object_obj_control_CreateEvent_3 (line 20) - room_goto(returnRoom)
pool = ds_list_create()
ds_list_insert(pool, 0, rm_roomOne)
ds_list_insert(pool, 1, rm_roomTwo)
ds_list_insert(pool, 2, rm_roomThree)
ds_list_insert(pool, 3, rm_roomFour)
var returnIndex;
var returnRoom;
returnIndex = irandom(ds_list_size(pool))
returnRoom = ds_list_find_value(pool, returnIndex)
if (ds_list_size(pool) == 0){
room_goto(rm_menu_screen)
}else{
room_goto(returnRoom)
}
I don't get the error message saying it's expecting a number.
This is weird indeed... I think this should actually work.. But I have no GM around to test :(
For now you can also solve this using "choose". This saves a list (and saves memory, because you're not cleaning up the list by deleting it - thus it resides in memory)
room_goto(choose(rm_roomOne, rm_roomTwo, rm_roomThree, rm_roomFour));
choose basically does exactly what you're looking for. Might not be the best way to go if you're re-using the group of items though.

Python 3 C-API IO and File Execution

I am having some serious trouble getting a Python 2 based C++ engine to work in Python3. I know the whole IO stack has changed, but everything I seem to try just ends up in failure. Below is the pre-code (Python2) and post code (Python3). I am hoping someone can help me figure out what I'm doing wrong.I am also using boost::python to control the references.
The program is supposed to load a Python Object into memory via a map and then upon using the run function it then finds the file loaded in memory and runs it. I based my code off an example from the delta3d python manager, where they load in a file and run it immediately. I have not seen anything equivalent in Python3.
Python2 Code Begins here:
// what this does is first calls the Python C-API to load the file, then pass the returned
// PyObject* into handle, which takes reference and sets it as a boost::python::object.
// this takes care of all future referencing and dereferencing.
try{
bp::object file_object(bp::handle<>(PyFile_FromString(fullPath(filename), "r" )));
loaded_files_.insert(std::make_pair(std::string(fullPath(filename)), file_object));
}
catch(...)
{
getExceptionFromPy();
}
Next I load the file from the std::map and attempt to execute it:
bp::object loaded_file = getLoadedFile(filename);
try
{
PyRun_SimpleFile( PyFile_AsFile( loaded_file.ptr()), fullPath(filename) );
}
catch(...)
{
getExceptionFromPy();
}
Python3 Code Begins here: This is what I have so far based off some suggestions here... SO Question
Load:
PyObject *ioMod, *opened_file, *fd_obj;
ioMod = PyImport_ImportModule("io");
opened_file = PyObject_CallMethod(ioMod, "open", "ss", fullPath(filename), "r");
bp::handle<> h_open(opened_file);
bp::object file_obj(h_open);
loaded_files_.insert(std::make_pair(std::string(fullPath(filename)), file_obj));
Run:
bp::object loaded_file = getLoadedFile(filename);
int fd = PyObject_AsFileDescriptor(loaded_file.ptr());
PyObject* fileObj = PyFile_FromFd(fd,fullPath(filename),"r",-1,"", "\n","", 0);
FILE* f_open = _fdopen(fd,"r");
PyRun_SimpleFile( f_open, fullPath(filename) );
Lastly, the general state of the program at this point is the file gets loaded in as TextIOWrapper and in the Run: section the fd that is returned is always 3 and for some reason _fdopen can never open the FILE which means I can't do something like PyRun_SimpleFile. The error itself is a debug ASSERTION on _fdopen. Is there a better way to do all this I really appreciate any help.
If you want to see the full program of the Python2 version it's on Github
So this question was pretty hard to understand and I'm sorry, but I found out my old code wasn't quite working as I expected. Here's what I wanted the code to do. Load the python file into memory, store it into a map and then at a later date execute that code in memory. I accomplished this a bit differently than I expected, but it makes a lot of sense now.
Open the file using ifstream, see the code below
Convert the char into a boost::python::str
Execute the boost::python::str with boost::python::exec
Profit ???
Step 1)
vector<char> input;
ifstream file(fullPath(filename), ios::in);
if (!file.is_open())
{
// set our error message here
setCantFindFileError();
input.push_back('\0');
return input;
}
file >> std::noskipws;
copy(istream_iterator<char>(file), istream_iterator<char>(), back_inserter(input));
input.push_back('\n');
input.push_back('\0');
Step 2)
bp::str file_str(string(&input[0]));
loaded_files_.insert(std::make_pair(std::string(fullPath(filename)), file_str));
Step 3)
bp::str loaded_file = getLoadedFile(filename);
// Retrieve the main module
bp::object main = bp::import("__main__");
// Retrieve the main module's namespace
bp::object global(main.attr("__dict__"));
bp::exec(loaded_file, global, global);
Full Code is located on github:

Resources