Pls help: problem with simple script

E

Enegris

Guest
so i was doing a tutorial on how to create an inventory for an rpg-game.
although i did precisely what i was being told by the tutorial, i got an errormessage for this script:

script: inv_init()

globalvar inv, invMax;

invMax = 30;


for(var i=0; i<invMax; i++)
{
inv[i,0] = 0
inv[i,1] = 0
}


the error message i get says:

___________________________________________
COMPILATION ERROR in Script: inv_init
Error in code at line 8:
for(var i=0; i<invMax; i++)
^
at position 11: Unexpected symbol in expression.

any idea what i've done wrong/ how i can fix this?
 
L

Lars Karlsson

Guest
Remove the 'var' in the 'var i = 0...' part and i believe it'll work.
 
Looks like you're using GM8.X. Declaring an iterator variable in the the for loop code isn't supported, nor is the use of ++. You'll have to rework your code to the following:

Code:
globalvar inv, invMax;

var i;

invMax = 30;


for(i=0; i<invMax; i += 1)
{
inv[i,0] = 0
inv[i,1] = 0
}
 

Zerb Games

Member
Looks like you're using GM8.X. Declaring an iterator variable in the the for loop code isn't supported, nor is the use of ++. You'll have to rework your code to the following:

Code:
globalvar inv, invMax;

var i;

invMax = 30;


for(i=0; i<invMax; i += 1)
{
inv[i,0] = 0
inv[i,1] = 0
}
Damn you beat me too it!
 
E

Enegris

Guest
thanks a lot for all your fast answers.
stained of mind : your assumption is correct, im using GM 8, at the moment the lite version. your fix did work, which is a relief, but i keep getting other error messages(i guess the root of the problem is the same), like:



___________________________________________
COMPILATION ERROR in Script: inv_add
Error in code at line 4:
found= -1
^
at position 7: Unexpected symbol in expression.




// this script is for adding items to inventory

var found
found= -1


var i;
for(i=0; i<invMax; i += 1)
{
if (inv[i,0] == argument0)
{
found = i
break
}
}



if(found == -1)
{
var i;
for(i=0; i<invMax; i += 1)
{
if(item[i,0]) == NOTHING)
{
found = i
break
}
}
}

inv[found, 0] = argument0
inv[found, 1] += argument1


is there a workaround?
 
You need to put a semi colon at the end of your 'var' declarations. This is the only place in GM, new or old, where the semi colon is actually required in order for things to function correctly. IE:

Code:
var found; // See the added semi colon here
found= -1
 
E

Enegris

Guest
stainedofmind : oh man, thank you so much, i really appreciate your help. i'm a rookie when it comes down to programming, so i get lost fast.
 
E

Enegris

Guest
EDIT: problem solved


stainedofmind : really sorry to bother you again. there is only one script left i need to make work in order to run it properly. i doublechecked the code and tried in a bungling manner to somehow "fix" it, but as expected, my effort was futile so far.


// this script is for showing items in inventory
var j;

for(j=0; j<invMax; j += 1)
{
draw_text(10,13*j,item[inv[j,0,],NAME] + " x " + string(inv[j, 1]))
}



___________________________________________
ERROR in
action number 1
of Draw Event
for object inventory:

In script inv_show:
Error in code at line 6:
draw_text(10,13*j,item[inv[j,0,],NAME] + " x " + string(inv[j, 1]))
^
at position 43: Wrong type of arguments to +.
 
Last edited by a moderator:
Top