M
markchapman
Guest
I'm having an issue with what I believe to be variable scope however it could be the way I'm assigning and calling the variable, Here is the error i get from gamemaker.
here is the script it is referring to.
This is where I'm calling the script in the step event of the object.
I'm not sure what is going on and if you need more info I Can give it to you, I thought that the scope of the script vars was for the script so why is it giving me an error about result? I need the diceRoll script to return A number so I didn't assign a variable to it, I'm not sure what is going on I hope it's something stupid simple, thanks in advanced.
GML:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object oCombatButton:
local variable result(100002, -2147483648) not set before reading it.
at gml_Script_diceRoll (line 10) - return result;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_diceRoll (line 10)
called from - gml_Object_oCombatButton_StepNormalEvent_1 (line 22) - case 0:showHitmarker(floor(room_width),floor(room_height),diceRoll(1,irandom(10)),2,c_blue,10);break;
GML:
////diceRoll(diceSides,rollAmount)
var result;
randomize()
for(var i=1;i<argument0;i++){
var result = irandom(argument1)
if result <= 0{
result+=1;
}
}
return result;
GML:
if keyYes{
switch(buttonState){
case 0:showHitmarker(floor(room_width),floor(room_height),diceRoll(1,irandom(10)),2,c_blue,10);break;
case 1:showHitmarker(floor(room_width),floor(room_height),diceRoll(1,irandom(10)),2,c_white,10);break;
case 2:showHitmarker(floor(room_width),floor(room_height),diceRoll(1,irandom(10)),2,c_red,10);break;
case 3:showHitmarker(floor(room_width),floor(room_height),diceRoll(1,irandom(10)),2,c_purple,10);break;
}
}